Sign in
agent:

Re-Open a ticket in Zendesk

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

This task changes the status of a previously solved or closed ticket back to 'open', enabling further actions or additional customer support interactions on that ticket.

import zenpy from zenpy.lib.api_objects import Ticket from zenpy.lib.exception import ZenpyException, APIException, RecordNotFoundException # Credentials for Zendesk API creds = _get_creds(cred_label)['creds'] ZENDESK_EMAIL = creds['username'] ZENDESK_TOKEN = creds['password'] #ZENDESK_SUBDOMAIN = 'your-subdomain' # Initialize Zenpy client client = zenpy.Zenpy(email=ZENDESK_EMAIL, token=ZENDESK_TOKEN, subdomain=ZENDESK_SUBDOMAIN) def reopen_ticket(ticket_id): """ Reopen a closed or solved ticket in Zendesk. :param ticket_id: ID of the ticket to be reopened. """ try: # Retrieve the ticket by ID ticket = client.tickets(id=ticket_id) # Ensure the ticket is a valid Ticket object if not isinstance(ticket, Ticket): print(f"Ticket ID {ticket_id} did not retrieve a valid Ticket object.") return # Check if the ticket is in 'solved' or 'closed' status if ticket.status in ['solved', 'closed']: ticket.status = 'open' client.tickets.update(ticket) print(f"Ticket {ticket_id} has been reopened.") else: print(f"Ticket {ticket_id} is not in a 'solved' or 'closed' status. Current status: {ticket.status}") except RecordNotFoundException: # Handle case where the ticket ID does not exist print(f"Ticket ID {ticket_id} does not exist.") except APIException as api_ex: # Handle API related exceptions print(f"APIException occurred: {api_ex}") except ZenpyException as zen_ex: # Handle other Zendesk related exceptions print(f"ZenpyException occurred: {zen_ex}") except Exception as e: # Catch-all for any other unexpected exceptions print(f"An unexpected error occurred: {e}") reopen_ticket(TICKET_ID_TO_UPDATE)
copied