Skip to content

Instantly share code, notes, and snippets.

@chucknado
Last active October 20, 2020 14:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chucknado/3d26957f348924bf9602 to your computer and use it in GitHub Desktop.
Save chucknado/3d26957f348924bf9602 to your computer and use it in GitHub Desktop.
A Python script for the article "Zendesk REST API tutorial: Searching" at https://support.zendesk.com/hc/en-us/articles/203691406
from urllib.parse import urlencode
import requests
credentials = 'your_zendesk_email', 'your_zendesk_password'
session = requests.Session()
session.auth = credentials
params = {
'query': 'type:ticket status:open',
'sort_by': 'created_at',
'sort_order': 'asc'
}
url = 'https://your_subdomain.zendesk.com/api/v2/search.json?' + urlencode(params)
response = session.get(url)
if response.status_code != 200:
print('Status:', response.status_code, 'Problem with the request. Exiting.')
exit()
# Print the subject of each ticket in the results
data = response.json()
for result in data['results']:
print(result['subject'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment