agent: |
H0KOvmf9Rx4GNd3Rh7ErAdd a private comment to a Zendesk ticket
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.
inputs
outputs
import 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.")
copied