Skip to content

Instantly share code, notes, and snippets.

@josh-padnick josh-padnick/script.sh
Last active Aug 31, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.