Last active
April 10, 2019 19:19
-
-
Save chucknado/88e6c270090d5ae03dc59367242a0efd to your computer and use it in GitHub Desktop.
Python module for Sunshine events in "Getting started with Sunshine user events" article
This file contains hidden or 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
import requests | |
credentials = 'your_zendesk_email', 'your_zendesk_password' | |
zendesk = 'https://your_subdomain.zendesk.com' | |
def track_event(payload): | |
url = f'{zendesk}/api/sunshine/events' | |
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} | |
response = requests.post(url, json=payload, auth=credentials, headers=headers) | |
if response.status_code != 202: | |
print(f'\nFailed to track event with error {response.status_code}: {response.text}') | |
return False | |
print(f'\nSuccessfully tracked event:\n{payload}') | |
return True | |
def search_events(internal_id): | |
url = f'{zendesk}/api/sunshine/events' | |
identifier = f'RationalTools:internal_id:{internal_id}' | |
params = {'identifier': identifier, 'source': 'RationalTools'} | |
headers = {'Accept': 'application/json'} | |
response = requests.get(url, params=params, auth=credentials, headers=headers) | |
if response.status_code != 200: | |
print(f'Failed to get events with error {response.status_code}: {response.text}') | |
return None | |
return response.json()['data'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment