Python script to retrieve Requester wait time of all open tickets on zendesk. | Community
Skip to main content

Python script to retrieve Requester wait time of all open tickets on zendesk.

  • December 13, 2023
  • 1 reply
  • 0 views

Shivani11

Hey Team,

I have written a custom Python script that connects Zendesk and Slack and posts all the open tickets with relevant information on the Slack channel. This trigger will contain all open tickets. Adding to the ticket information I also need the requester wait time data for each ticket, tried all the values and keys but I am still getting the requester wait time value as N/A or 0.0 hours. 

I referred to this JSON format here in this doc https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_metric_events/ for reference.

 I am also sharing some sample code that I tried :  

Script1

# Prepare a message for Slack message = "Requester Wait Time for Open Tickets:\n" for ticket in tickets: ticket_id = ticket['id'] # Fetch requester wait time (RWT) data requester_wait_time = 'N/A' # Check if 'metric_events' is present in the ticket data metric_events = ticket.get('metric_events', []) # Find the activate event for requester wait time metric activate_event = next((event for event in metric_events if event['metric'] == 'requester_wait_time' and event['type'] == 'activate'), None) if activate_event: activate_time = activate_event.get('time') activate_datetime = datetime.strptime(activate_time, "%Y-%m-%dT%H:%M:%S") requester_wait_time = datetime.now() - activate_datetime # Format requester wait time days, seconds = requester_wait_time.days, requester_wait_time.seconds hours = seconds // 3600 requester_wait_time = f"{days} days, {hours} hours" # Add ticket information to the message message += f"Ticket ID: {ticket_id}\nRequester Wait Time: {requester_wait_time}\n\n"

Script2

# Fetch requester wait time (RWT) data requester_wait_time = 'N/A' # Check if 'requester_wait_time_in_minutes' is present in the ticket data rwt_data = ticket.get('requester_wait_time_in_minutes', None) if rwt_data: business_time = rwt_data.get('business', 0) calendar_time = rwt_data.get('calendar', 0) # Convert minutes to timedelta for better readability business_timedelta = datetime.timedelta(minutes=business_time) calendar_timedelta = datetime.timedelta(minutes=calendar_time) requester_wait_time = { 'business': str(business_timedelta), 'calendar': str(calendar_timedelta) } # Add ticket information to the message message += f"Ticket ID: {ticket_id}\nRequester Wait Time: {requester_wait_time}\n\n" 

 

Script3 : 

# Fetch requester wait time (RWT) data metrics = ticket.get('metric_events', []) requester_wait_time = 'N/A' for metric in metrics: if metric.get('metric') == 'requester_wait_time': requester_wait_time = metric.get('value', 'N/A') break 

Can you please help me with the correct key or ID to fetch the requester wait time data for all the tickets from Zendesk API? since this data is available on Zendesk, there should be a way to retrieve this.

1 reply

Hi Shivani,
 
You can return the calculated requester wait time for an individual ticket using the Show Ticket Metrics endpoint.  If you're already exporting tickets using the Incremental Ticket Export API, you can include those same ticket metrics in the response by side-loading metric_sets.