Skip to content

Instantly share code, notes, and snippets.

@josh-padnick josh-padnick/
Last active Aug 31, 2017

What would you like to do?
Compute the number of hours used by a customer for a given date range in Zendesk
# 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
# 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_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.
curl --request GET \
--silent --show-error \
--url${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
You can’t perform that action at this time.