Sign in

Create a webhook in Zendesk to send a request to DagKnows

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 create a webhook in Zendesk def create_webhook(email, api_token, subdomain, webhook_url, dagknows_token): # Define the endpoint URL for creating webhooks url = f'https://{subdomain}.zendesk.com/api/v2/webhooks' # Define the headers including the authorization headers = { 'Content-Type': 'application/json' } # Define the webhook payload payload = { 'webhook': { 'name': 'Keyword Triggered Webhook', 'endpoint': webhook_url, 'http_method': 'POST', 'request_format': 'json', 'status': 'active', 'subscriptions': [ "conditional_ticket_events" ], "authentication": { "type": "bearer_token", "data": { "token": dagknows_token }, "add_position": "header" } } } # Make the request to create the webhook response = requests.post(url, auth = HTTPBasicAuth(email + '/token', api_token), headers=headers, json=payload) # Check if the request was successful if response.status_code == 201: return {'success': True, 'webhook_id': response.json()['webhook']['id']} else: print(response.status_code) return {'success': False, 'error': response.text} creds = _get_creds(zendesk_cred_label)['creds'] api_token = creds['password'] email = creds['username'] dkcreds = _get_creds(dagknows_cred_label)['creds'] dagknows_token = dkcreds['password'] op = create_webhook(email, api_token, subdomain, webhook_url, dagknows_token) print("Response: ", op) webhook_id = "" if op['success']: webhook_id = op['webhook_id']
copied