Skip to content

Instantly share code, notes, and snippets.

@chucknado
Last active April 10, 2019 22:35
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/47fb82628c0c9def41dbefd18b3df656 to your computer and use it in GitHub Desktop.
Save chucknado/47fb82628c0c9def41dbefd18b3df656 to your computer and use it in GitHub Desktop.
Python module for Sunshine profiles in "Getting started with Sunshine profiles" article
import requests
credentials = 'your_zendesk_email', 'your_zendesk_password'
zendesk = 'https://your_subdomain.zendesk.com'
def post_profile(profile):
data = {'profile': profile}
url = f'{zendesk}/api/sunshine/profile'
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
response = requests.post(url, json=data, auth=credentials, headers=headers)
if response.status_code != 202:
print(f'\nFailed to post profile with error {response.status_code}: {response.text}')
return False
print(f'\nSuccessfully posted profile.\n')
return True
def get_profile(profile_source, profile_type, identifier_name, identifier_value):
url = f'{zendesk}/api/sunshine/profile'
identifier_query = f'{profile_source}:{profile_type}:{identifier_name}:{identifier_value}'
params = {'identifier': identifier_query}
headers = {'Accept': 'application/json'}
response = requests.get(url, params=params, auth=credentials, headers=headers)
if response.status_code != 200:
print(f'Failed to get profile with error {response.status_code}: {response.text}')
exit()
return response.json()['data']
def list_people():
url = f'{zendesk}/api/sunshine/people'
headers = {'Accept': 'application/json'}
response = requests.get(url, auth=credentials, headers=headers)
if response.status_code != 200:
print(f'Failed to get profile with error {response.status_code}: {response.text}')
exit()
return response.json()['data']['people']
def get_person(profile_source, profile_type, identifier_name, identifier_value):
url= f'{zendesk}/api/sunshine/person'
identifier_query = f'{profile_source}:{profile_type}:{identifier_name}:{identifier_value}'
params = {'identifier': identifier_query}
headers = {'Accept': 'application/json'}
response = requests.get(url, params=params, auth=credentials, headers=headers)
if response.status_code != 200:
print(f'Failed to get person with error {response.status_code}: {response.text}')
exit()
return response.json()['data']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment