Sign in
agent:

Add a trigger for every Zendesk Ticket created in DevOps group, Status can be new or open

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
import requests import json from requests.auth import HTTPBasicAuth # Usage creds = _get_creds(zendesk_cred_label)['creds'] api_token = creds['password'] email = creds['username'] # Function to get group ID by name def get_group_id(subdomain, email, api_token, group_name): api_url = f'https://{subdomain}.zendesk.com/api/v2/groups.json' headers = { 'Content-Type': 'application/json' } basic_auth = HTTPBasicAuth(f'{email}/token', api_token) response = requests.get(api_url, auth=basic_auth, headers=headers) if response.status_code == 200: groups = response.json().get('groups', []) for group in groups: if group['name'].lower() == group_name.lower(): return group['id'] return None # Function to add a trigger to Zendesk def add_zendesk_trigger_for_new_ticket(api_url, email, api_token, webhook_id, group_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 or open ticket creation in DevOps group', 'conditions': { 'all': [ { 'field': 'group_id', 'operator': 'is', 'value': str(group_id) } ], 'any': [ { 'field': 'status', 'operator': 'is', 'value': 'new' }, { 'field': 'status', 'operator': 'is', 'value': 'open' } ] }, '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() # Get the group ID for "DevOps" group_id = get_group_id(subdomain, email, api_token, 'DevOps') if group_id: 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, group_id) print(status_code) print(json.dumps(response_json, indent=4)) else: print("Group 'DevOps' not found.")
copied