-
Notifications
You must be signed in to change notification settings - Fork 65
Add last changed API #51
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -712,6 +712,30 @@ def get_meta_users(self): | |
|
||
return r.json() | ||
|
||
def get_last_changed(self, iso_timestamp): | ||
""" | ||
API method for discovering which employees have been recently added, changed or deleted. | ||
https://www.bamboohr.com/api/documentation/changes.php | ||
@param iso_timestamp: get last changed since this ISO 8601 timestamp | ||
|
||
@return: dictionary with employees which have been changed recently | ||
""" | ||
|
||
url = self.base_url + "employees/changed/" | ||
payload = { | ||
'since': "{}".format(iso_timestamp) | ||
} | ||
# Convert payload to stop percent encoding the URL for requests | ||
payload_str = "&".join("%s=%s" % (k,v) for k,v in payload.items()) | ||
|
||
r = requests.get(url, timeout=self.timeout, headers=self.headers, params=payload_str, auth=(self.api_key, '')) | ||
r.raise_for_status() | ||
|
||
last_changed = r.json() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. possible crash bug if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but I'd open a different issue for to improve the code because this affects all API methods. @vahedq could you open an new issue with this? And if you have a fix at hand, a PR would be highly appreciated 😬 Nevertheless, it is expected that BambooHR answers with a JSON, so not critical. |
||
|
||
return last_changed | ||
|
||
|
||
def _query(self, url, params, raw=False): | ||
url = self.base_url + url | ||
r = requests.get(url, timeout=self.timeout, params=params, headers=self.headers, auth=(self.api_key, '')) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,3 +93,20 @@ bamboo = PyBambooHR(subdomain='yoursub', api_key='yourapikeyhere', only_current= | |
|
||
``` | ||
BambooHR has effective dates for when promotions are scheduled to happen or when new hires are going to join the organization. In order to see these events before they happen using the BambooHR API set `only_current` to `False`. As a note, this only works for pulling reports and getting employee information. This does not work on getting the employee directory. | ||
|
||
|
||
Getting last changed | ||
```python | ||
from PyBambooHR import PyBambooHR | ||
|
||
bamboo = PyBambooHR(subdomain='yoursub', api_key='yourapikeyhere') | ||
|
||
# Date in ISO 8601, 15 minutes ago | ||
since_time = (datetime.datetime.now() - datetime.timedelta(minutes=15)).replace(microsecond=0) | ||
since_time_iso = since_time.strftime('%Y-%m-%dT%H:%M:%SZ') | ||
|
||
result = get_last_changed(since_time_iso) | ||
|
||
``` | ||
|
||
Note: Last change timestamps are a newer feature in BambooHR, and they only started recording these dates from June 5th, 2011. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2011 is quite some time ago. I think it's fine to drop this info from the README 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you pass
params=payload
instead of building the string. Compare https://requests.readthedocs.io/en/master/user/quickstart/#passing-parameters-in-urls