Skip to content

Instantly share code, notes, and snippets.

@josh-padnick
Last active August 31, 2017 19:33
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 josh-padnick/945032b09d1e8e4a6b50f9ff4984d103 to your computer and use it in GitHub Desktop.
Save josh-padnick/945032b09d1e8e4a6b50f9ff4984d103 to your computer and use it in GitHub Desktop.
Compute the number of hours used by a customer for a given date range in Zendesk
#!/bin/bash
# 1. Make sure obtain an API Token
# 2. This has only been validated to work with ZenDesk agents, not end users
# 3. Look up the customer's org ID by querying https://gruntwork.zendesk.com/api/v2/organizations.json
# 4. Look up the ZenDesk custom Field ID that stores the number of hours used by querying a complete ticket and inspecting the JSON output
# 5. This script all automatically sum the total of all numbers in the given month and ignore empty numbers.
zendesk_username="josh@gruntwork.io/token"
zendesk_password="<enter-your-api-token>"
zendesk_org_id=115105505733 # Get this by doing another ZenDesk query
zendesk_hours_field_id=114096573774 # This is the unique ID of a custom field you have in ZenDesk.
zendesk_start_date="2017-08-01"
zendesk_end_date="2017-08-31"
curl --request GET \
--silent --show-error \
--url https://gruntwork.zendesk.com/api/v2/organizations/${zendesk_org_id}/tickets.json \
--user ${zendesk_username}:${zendesk_password} \
| jq --raw-output ".tickets[] | select((.created_at >= \"${zendesk_start_date}\") and (.created_at <= \"${zendesk_end_date}\")) | .custom_fields[] | select(.id == ${zendesk_hours_field_id}) | .value" \
| grep -v "null" \
| awk '{s+=$1} END {print "==> " s " Total support hours have been used in the specified time range!"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment