Sign in

Add a Zendesk trigger for a keyword in a ticket subject

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


import requests from requests.auth import HTTPBasicAuth # Function to add a trigger to Zendesk def add_zendesk_trigger(api_url, email, api_token, keyword, webhook_id): headers = { 'Content-Type': 'application/json' } data_to_send = """ { "id" : "{{ticket.id}}", "subject" : "{{ticket.subject}}", "latest_comment" : "{{ticket.description}}" } """ data = { 'trigger': { 'title': f'Trigger for keyword {keyword}', 'conditions': { 'all': [ {'field': 'subject', 'operator': 'contains', 'value': keyword} ] }, 'actions': [ { 'field': 'notification_webhook', 'value': [webhook_id, data_to_send] } ] } } basic_auth = HTTPBasicAuth(email + '/token', api_token) response = requests.post(api_url, auth = basic_auth, headers=headers, json=data) return response.status_code, response.json() api_url = f'https://{subdomain}.zendesk.com/api/v2/triggers' creds = _get_creds(zendesk_cred_label)['creds'] api_token = creds['password'] email = creds['username'] status_code, response_json = add_zendesk_trigger(api_url, email, api_token, keyword, webhook_id) print(status_code) print(json.dumps(response_json, indent=4))
copied