agent: |
qmjA8b1ngcPssfNalnFTAdd a trigger for every Zendesk ticket created
Add a trigger for every Zendesk ticket created
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
inputs
outputs
import requests
import json
from requests.auth import HTTPBasicAuth
# Function to add a trigger to Zendesk
def add_zendesk_trigger_for_new_ticket(api_url, email, api_token, webhook_id):
headers = {
'Content-Type': 'application/json'
}
data_to_send = """
{
"id" : "{{ticket.id}}",
"subject" : "{{ticket.subject}}",
"description" : "{{ticket.description}}",
"created_at" : "{{ticket.created_at}}",
"updated_at" : "{{ticket.updated_at}}",
"priority" : "{{ticket.priority}}",
"status" : "{{ticket.status}}",
"assignee_id" : "{{ticket.assignee_id}}",
"requester_id" : "{{ticket.requester_id}}",
"organization_id" : "{{ticket.organization_id}}"
}
"""
data = {
'trigger': {
'title': 'Trigger for new ticket creation',
'conditions': {
'all': [
{
'field': 'status',
'operator': 'is',
'value': 'new'
}
]
},
'actions': [
{
'field': 'notification_webhook',
'value': [webhook_id, data_to_send]
}
]
}
}
basic_auth = HTTPBasicAuth(f'{email}/token', api_token)
response = requests.post(api_url, auth=basic_auth, headers=headers, json=data)
return response.status_code, response.json()
# Usage
creds = _get_creds(zendesk_cred_label)['creds']
api_token = creds['password']
email = creds['username']
api_url = f'https://{subdomain}.zendesk.com/api/v2/triggers.json'
status_code, response_json = add_zendesk_trigger_for_new_ticket(api_url, email, api_token, webhook_id)
print(status_code)
print(json.dumps(response_json, indent=4))
copied