2

I've been trying to retrieve data on the reply time of my agents through the Zendesk API. However, every time I use the given metric "reply_time_in_minutes" I get a KeyError. Does anyone have suggestions on what I should do?

import requests
# Set the request parameters
url = 'https://domain.zendesk.com/api/v2/incremental/tickets.json? 
start_time=1563230494'
user = 'email' + '/token'
pwd = 'token'

# Do the HTTP get request
response = requests.get(url, auth=(user, pwd))

# Check for HTTP codes other than 200
if response.status_code != 200:
    print('Status:', response.status_code, 'Problem with the request. 
    Exiting.')
    exit()

# Decode the JSON response into a dictionary and use the data
data = response.json()

ticket_list1 = data['tickets']

for ticket1 in ticket_list1:
    print(ticket1['reply_time_in_minutes'])
snnr
  • 27
  • 6
  • 1
    What do you mean by `a 404 problem`? You are simply trying to access a value in a dictionary, not making an http request. Post the error message with full traceback, if any. – Selcuk Jul 30 '19 at 00:07
  • If you mean 404 Error when saying 404 Problem, something is not available, as 404 is not found. So maybe something is wrong with your url or the user doesn't exist or something similar. But for more we need an exact errormessage – Flo Jul 30 '19 at 14:25
  • Sorry, I wrote 404 problem by mistake. This is the message I receive "Traceback (most recent call last): File "/Users/snnr/PycharmProjects/name/app.py", line 39, in print(ticket1['reply_time_in_minutes']) KeyError: 'reply_time_in_minutes'" – snnr Jul 30 '19 at 14:28

1 Answers1

0

'reply_time_in_minutes' is a ticket metric that is not available in the incremental ticket export endpoint you are using. To get the data on metrics you need to 'sideload' the metric_sets using

url = 'https://domain.zendesk.com/api/v2/incremental/tickets.json? 
start_time=1563230494&include=metric_sets'
craigts
  • 2,857
  • 1
  • 25
  • 25