-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script to populate the webhook_id in Bamboohr (#141)
* Script to populate the webhook_id in Bamboohr * resolved comment
- Loading branch information
1 parent
2a1740c
commit 3999dbb
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from apps.bamboohr.models import BambooHr | ||
from bamboosdk.bamboohrsdk import BambooHrSDK | ||
from admin_settings.settings import API_URL | ||
|
||
all_bamboohr = BambooHr.objects.filter(api_token__isnull=False, sub_domain__isnull=False) | ||
|
||
for bamboohr in all_bamboohr: | ||
|
||
try : | ||
bamboohrsdk = BambooHrSDK(api_token=bamboohr.api_token, sub_domain=bamboohr.sub_domain) | ||
|
||
webhook_payload = { | ||
'postFields': { | ||
'firstName': 'firstName', | ||
'lastName': 'lastName', | ||
'department': 'department', | ||
'workEmail': 'workEmail', | ||
'status': 'status', | ||
'reportingTo': 'reportingTo' | ||
}, | ||
'name': bamboohr.org.name, | ||
'monitorFields': ['firstName', 'lastName', 'department', 'workEmail', 'status', 'reportingTo'], | ||
'url': API_URL + f'/orgs/{bamboohr.org.id}/bamboohr/webhook_callback/', | ||
'format': 'json' | ||
} | ||
|
||
response = bamboohrsdk.webhook.post(payload=webhook_payload) | ||
BambooHr.objects.filter(id=bamboohr.id).update(webhook_id=int(response['id'])) | ||
|
||
except Exception as e: | ||
print(f'For org_id {bamboohr.org.id} error occured', e) |