Cm62BMsuhNatt9RXAL7XAdd a public comment to a Zendesk Ticket
Add a public comment to a Zendesk Ticket
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
inputs
outputs
import zenpy
from zenpy.lib.exception import ZenpyException
# Credentials for Zendesk API
creds = _get_creds(cred_label)['creds'] # Assuming the function _get_creds retrieves the necessary credentials
ZENDESK_EMAIL = creds['username']
ZENDESK_TOKEN = creds['password']
ZENDESK_SUBDOMAIN = subdomain # Replace with your subdomain
# Initialize Zenpy client
client = zenpy.Zenpy(email=ZENDESK_EMAIL, token=ZENDESK_TOKEN, subdomain=ZENDESK_SUBDOMAIN)
def update_ticket_with_public_comment(ticket_id, update_fields):
"""
Update a Zendesk ticket with a public comment.
Parameters:
- ticket_id: The ID of the ticket to update.
- update_fields: A dictionary containing the fields to update, including the comment.
"""
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=True) # Set comment to public
# 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
# Example usage
#TICKET_ID_TO_UPDATE = '3' # Replace with your ticket ID
UPDATE_FIELDS = {
'comment': comment # Replace with your comment
# Add other fields as needed
}
# Update the ticket with a public comment
if update_ticket_with_public_comment(TICKET_ID_TO_UPDATE, UPDATE_FIELDS):
print(f"Ticket {TICKET_ID_TO_UPDATE} updated with a public comment successfully.")
else:
print("Failed to update ticket with a public comment.")
copied