Skip to content

Instantly share code, notes, and snippets.

@chucknado
Last active April 10, 2019 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chucknado/88e6c270090d5ae03dc59367242a0efd to your computer and use it in GitHub Desktop.
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
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