
Question
How can I expose Time Tracking app data via the API?
Answer
1. Locate the field IDs for each of the custom ticket fields created by the time tracking app. To do this, go to the ticket fields endpoint and search for each of the following field names:
- Time spent last update (sec)
- Total time spent (sec)
You can also gather this information by going to Admin () > Manage > Ticket Fields. You will see a list of your ticket fields and the field IDs are displayed in the column Field ID.
2. Record the IDs somewhere you can easily access them.
3. Use the ticket audits endpoint to retrieve the fields' data. The data is recorded in seconds. Keep in mind that the audits endpoint stores the time tracking data under their field IDs, not their field names.
Note: If you just want the end-state of the time tracking values, you will need to write a script to look at the last event in the ticket audit. If you want historical information for each ticket update, you will want your script to grab the values of these fields in each event.
15 Comments
If you're looking for significantly more detailed time data, you can find it via Ticket Audits: https://developer.zendesk.com/rest_api/docs/core/ticket_audits
Note that it's somewhat buried...
{
"id": <AUDIT ID>
...
"events": [
{
"id": <EVENT ID>
"type": "Change",
"value": 360, (this is the NEW TOTAL)
"field_name": <YOUR TOTAL TIME SPENT FIELD ID>,
"previous_value": 0 (this is the value it was before)
},
...
]
...
}
Want to know how much time for each "event"? Just subtract "value" from "previous_value".
Thanks for the info, Adam!
How do you get the date and id/name of the person who did that time entry?
I can get the time, but can't tell for whom it comes...
How can you link Time Tracking app field with ticket_audits? What's the key field that links them?
Thank you
Edward,
It looks to me like you're pulling the field info--not the audit.
The audit "events" contains the "author_id". Use:
https://[DOMAIN].zendesk.com/api/v2/tickets/[TICKET]/audits.json
Then check out my notes above.
Adam
Adam
Hi Adam,
Thank you very much for the quick answer, much appreciated.
Indeed, that screenshot is from the field info, I was wondering where it says it's a Time Tracking object.
The author_id is the one that created the audits entry, so he also created the Time Tracking entry on the date_time. Is that correct?
Yep, sure is!
Many thanks :)
I'm wanting to hook the Time Tracking App into another modal on ticket closure. Problem being that there can only be one modal at a time (is this correct? how would it display otherwise?)
Hi Andrew,
For apps that were written in Apps framework v2, there can only be one modal open at a time.
If multiple apps all have ticket.save events that bring up modals (such as the Time Tracking app) then when one modal from one apps is closed, the next modal from the next app in the ticket.save event chain will open.
If this doesn't get you going in the right direction, please share any additional use-case details and maybe some other way can be found.
Thanks Bryan, can I email you? We're wanting to do a number of apps that pop a modal on close or save. Chains of modals is going to be really messy and annoying for agents. I'm hoping to find a way to display all at once and have one button affect all.
Another possibility is to have a central app that pulls in the requirements of the other installed apps, so that they aren't popping their own modal... Your thoughts?
I'll open a ticket on your behalf Andrew and we can talk on the side. It sounds like the last idea of pulling in requirements of other installed apps is the way to go (but would require that you control those apps as you can't suppress ticket.save events or modals from other apps).
So I can get the "Total time spent" off the ticket via a custom field. And I can see through this thread that, using Ticket Audit events, I can get all the "Change" events which contain each time tracking entry value, and per authorId (from the parent Audit object). All that's great, and I have that working. What I can't figure out is how to determine _when_ those hours were logged. Specifically, I want to know how many hours were logged by agents in a period of time (last week, or last month), and I can't seem to figure that out. What am I missing? Any assistance is appreciated. Thanks.
There should be a "created_at" field in each of the audits.
Would it be possible to build a Trigger and a URL Post target to send the Event data in Realtime to another system (i.e. Salesforce).
We have a Time Entry package in Salesforce where we can configure a an interface. I would like to use this information to help build my Agents Timesheets
HeyO Jeff,
Our current SFDC integration does basically this exact thing by leveraging a custom ticket object. For more information on configuring this feature of the integration, please see https://support.zendesk.com/hc/en-us/articles/203660006
More generally, this workflow should definitely be possible, although I'd recommend the use of an HTTP target (rather than the URL target) because it's easier to see/manipulate the format of the data being sent. For more information about this type of workflow, please see https://support.zendesk.com/hc/en-us/articles/204890268-Creating-webhooks-with-the-HTTP-target
Hopefully this helps to answer your question!
Please sign in to leave a comment.