agent: |
Zendesk Basic Integration Tasks
- 1E4C49POYLRB2dQkZptQaView a Zendesk Ticket by Id
1
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.This task retrieves detailed information of a specific ticket from Zendesk using its unique ticket ID, allowing for quick access and review of individual ticket details.
inputsoutputsimport zenpy from zenpy.lib.exception import ZenpyException # Credentials for Zendesk API creds = _get_creds(cred_label)['creds'] ZENDESK_EMAIL = creds['username'] ZENDESK_TOKEN = creds['password'] #ZENDESK_SUBDOMAIN = 'your-zendesk-subdomain' #TICKET_ID_TO_VIEW = '3' # Replace with your ticket ID # Initialize Zenpy client client = zenpy.Zenpy(email=ZENDESK_EMAIL, token=ZENDESK_TOKEN, subdomain=ZENDESK_SUBDOMAIN) def view_ticket(ticket_id): """ View a Zendesk ticket by its ID. """ try: # Retrieve the ticket from Zendesk ticket = client.tickets(id=ticket_id) return ticket except ZenpyException as e: print(f"ZenpyException occurred: {e}") except Exception as e: print(f"An error occurred: {e}") return None def print_ticket_details(ticket): """ Print details of a Zendesk ticket. """ print(f"Ticket ID: {ticket.id}") print(f"Subject: {ticket.subject}") print(f"Description: {ticket.description}") print(f"Status: {ticket.status}") print(f"Priority: {ticket.priority}") print(f"Requester ID: {ticket.requester_id}") print(f"Assignee ID: {ticket.assignee_id}") print(f"Created at: {ticket.created_at}") print(f"Updated at: {ticket.updated_at}") # Add any other fields you want to display # View the ticket ticket = view_ticket(TICKET_ID_TO_VIEW) if ticket: print_ticket_details(ticket) else: print("Failed to retrieve ticket.")copied1 - 2bmBPzc3TgFjOzUzkXRqdRe-Open a ticket in Zendesk
2
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.
inputsoutputsimport 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)copied2 - 3yVNLxaYN8atzQuGYIY7xMark Ticket as Solved in Zendesk
3
Mark Ticket as Solved in Zendesk
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.This task updates the status of a selected ticket to 'solved', indicating the issue has been addressed and resolved in the Zendesk support system.
inputsoutputsimport zenpy from zenpy.lib.exception import ZenpyException, RecordNotFoundException, APIException # 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 mark_ticket_solved(ticket_id): """ Marks a Zendesk ticket as solved. Args: ticket_id (int): The ID of the ticket to be marked as done. The function checks if the ticket exists and is in a markable state (i.e., not already solved or closed), then updates its status to 'solved'. """ try: # Retrieve the ticket by its ID ticket = client.tickets(id=ticket_id) # Check if the ticket is already in a final state (solved or closed) if ticket.status in ['solved', 'closed']: print(f"Ticket {ticket_id} is already marked as {ticket.status}.") return # Update the ticket status to 'solved' ticket.status = 'solved' client.tickets.update(ticket) print(f"Ticket {ticket_id} has been marked as done (solved).") except RecordNotFoundException: # Handle case where the ticket ID does not exist print(f"Ticket ID {ticket_id} does not exist in Zendesk.") 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}") mark_ticket_solved(TICKET_ID_TO_UPDATE)copied3 - 4op5SR8wlFL85HCd0MEHbAssign a Ticket to a User in Zendesk
4
Assign a Ticket to a User in Zendesk
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.This is a task where a specific Zendesk ticket is allocated to a designated user or agent for resolution, ensuring targeted and efficient handling of customer queries or issues.
inputsoutputsimport zenpy from zenpy.lib.exception import ZenpyException, RecordNotFoundException, APIException # 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 assign_ticket_to_user(ticket_id, assignee_id, priority='normal'): """ Assigns a ticket to a specified user in Zendesk and sets the priority, if needed. Args: ticket_id (int): The ID of the ticket to be assigned. assignee_id (int): The ID of the user to whom the ticket will be assigned. priority (str): The priority of the ticket ('urgent', 'high', 'normal', 'low'). The function verifies the existence of the ticket and the user before proceeding with the assignment. If the ticket is already assigned to the specified user with the same priority, it informs the user. """ try: # Retrieve the ticket by its ID ticket = client.tickets(id=ticket_id) if not ticket: print(f"Ticket with ID {ticket_id} does not exist.") return # Check if the user exists and is active in Zendesk user = client.users(id=assignee_id) if not user or user.active is False: print(f"User with ID {assignee_id} does not exist or is inactive.") return # Check if the ticket is already assigned with the same priority if ticket.assignee_id == assignee_id and ticket.priority == priority: print(f"Ticket {ticket_id} is already assigned to user {assignee_id} with priority {priority}. No changes made.") return # Assign the ticket to the user and set the priority ticket.assignee_id = assignee_id ticket.priority = priority client.tickets.update(ticket) print(f"Ticket {ticket_id} has been assigned to user {assignee_id} with priority {priority}.") except RecordNotFoundException: print(f"Ticket ID {ticket_id} or User ID {assignee_id} does not exist in Zendesk.") except APIException as api_ex: print(f"APIException occurred: {api_ex}") except ZenpyException as zen_ex: print(f"ZenpyException occurred: {zen_ex}") except Exception as e: print(f"An unexpected error occurred: {e}") # Example Usage # Replace the ticket ID and user ID with valid values #TICKET_ID_TO_UPDATE = 3 #user_id = 16645863103762 assign_ticket_to_user(TICKET_ID_TO_UPDATE, user_id, priority='high')copied4 - 5H0KOvmf9Rx4GNd3Rh7ErAdd a private comment to a Zendesk ticket
5
Add a private comment to a Zendesk ticket
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.This task is designed to append a non-public, internal comment to a specific Zendesk ticket, facilitating internal team communications and notes without exposing the information to the ticket requester.
inputsoutputsimport zenpy from zenpy.lib.exception import ZenpyException # Credentials for Zendesk API creds = _get_creds(cred_label)['creds'] ZENDESK_EMAIL = creds['username'] ZENDESK_TOKEN = creds['password'] #TICKET_ID_TO_UPDATE = '3' # Replace with your ticket ID UPDATE_FIELDS = { 'comment': comment # Add other fields as needed } # Initialize Zenpy client client = zenpy.Zenpy(email=ZENDESK_EMAIL, token=ZENDESK_TOKEN, subdomain=ZENDESK_SUBDOMAIN) def update_ticket(ticket_id, update_fields): """ Update a Zendesk ticket with the given fields. Parameters: - ticket_id: The ID of the ticket to update. - update_fields: A dictionary containing the fields to update, including comments. """ try: # Retrieve the ticket by ID ticket = client.tickets(id=ticket_id) # Update fields of the ticket for key, value in update_fields.items(): if key.lower() == 'subject': ticket.subject = value elif key.lower() == 'comment': # Special handling for comments ticket.comment = zenpy.lib.api_objects.Comment(body=value, public=False) # Add other fields handling as needed # Update the ticket in Zendesk client.tickets.update(ticket) return True except ZenpyException as e: print(f"ZenpyException occurred: {e}") return False except Exception as e: print(f"An error occurred: {e}") return False # Update the ticket if update_ticket(TICKET_ID_TO_UPDATE, UPDATE_FIELDS): print(f"Ticket {TICKET_ID_TO_UPDATE} updated successfully.") else: print("Failed to update ticket.")copied5 - 6NKm475RZeR125xoUVpWSList Tickets resolved by a User in Zendesk
6
List Tickets resolved by a User in Zendesk
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.This task involves generating a summary of all tickets that a specific user or agent has successfully resolved, providing a clear record of their contributions and performance in handling customer issues.
inputsoutputsimport zenpy from zenpy.lib.exception import ZenpyException # 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 list_tickets_resolved_by_user(user_id): """ List tickets resolved by a specified user in Zendesk. Args: user_id (int): The ID of the user. Returns: List of ticket IDs resolved by the user. """ resolved_tickets = [] try: # Search for tickets that are resolved and were assigned to the given user for ticket in client.search(type='ticket', status='solved', assignee_id=user_id): resolved_tickets.append(ticket.id) if resolved_tickets: print(f"Resolved tickets by user {user_id}: {resolved_tickets}") else: print(f"No resolved tickets found for user {user_id}.") except ZenpyException as e: print(f"An error occurred while retrieving tickets: {e}") return resolved_tickets # Replace with a valid user ID #user_id = 16645863103762 list_tickets_resolved_by_user(user_id)copied6