I am trying to write a script that will outputs the following:
if group_id == 6177821616923
output ticket_id, created_at, reply_time_in_minutes, on_hold_time_in_minutes
What's happening is that each time my script outputs, it outputs the same ticket ID for each iteration. I am sure this is something small. I am trying to map these API's together based on the ticket ID. Open to suggestions on how to make this better and more efficient.
import requests
# Constants
AUTH = 'andrew.e@coinmetrics.io/token', 'my_key'
HEADERS = {"Content-Type": "application/json"}
def cse_tickets(ticket_id):
url = "https://coinmetricshelp.zendesk.com/api/v2/tickets/"
response = requests.get(url, auth=AUTH, headers=HEADERS)
if response.status_code == 200:
data = response.json()
tickets = data.get('tickets')
for ticket in tickets:
if ticket['group_id'] == 6177821616923:
ticket_id = ticket.get('id')
return ticket_id
else:
return None
def first_response_time():
url = "https://coinmetricshelp.zendesk.com/api/v2/ticket_metrics"
response = requests.get(url, auth=AUTH, headers=HEADERS)
if response.status_code == 200:
data = response.json()
tickets = data.get('ticket_metrics')
for ticket in tickets:
ticket_id = ticket.get('ticket_id')
created_at = ticket.get('created_at')
first_reply = ticket.get("reply_time_in_minutes")['calendar']
on_hold = ticket.get("on_hold_time_in_minutes")['calendar']
cse = cse_tickets(ticket_id)
print(f"Ticket ID: {cse} Created At: {created_at} First Reply: {first_reply}")
first_response_time()
An example of the output is below:
Ticket ID: 534 Created At: 2024-04-22T13:06:12Z First Reply: None
Ticket ID: 534 Created At: 2024-04-19T13:36:18Z First Reply: 0
Ticket ID: 534 Created At: 2024-04-19T13:12:33Z First Reply: 0
Ticket ID: 534 Created At: 2024-04-17T13:04:42Z First Reply: 1
Ticket ID: 534 Created At: 2024-04-17T12:27:31Z First Reply: 1197
Hi Ned,
Thanks for the response. Your amendment has helped me.
I've also added pagination.