Using WebHooks to create Zendesk Tickets with Group Assignment and Custom Fields
The webhook example code below, will create a Zendesk ticket from a form submission using the node-zendesk module. Webhooks are an Enteprise Plus plan feature.
In order to integrate with Zendesk , you will need to use a zendesk user account and retrieve an API token from Zendesk .
Getting a Zendesk API Token
Zendesk API tokens are used in authentication for Zendesk API requests. To create an API token, go to the Zendesk Admin Center by clicking the four squares in the top-right of the page and then clicking the Admin Center link. Next click API tokens management pages under Apps and integrations > APIs > Zendesk API.
This will bring you to the API page. From here, click the white Add API token button. Enter a description for the new API key, copy the token it generated, and click the Save button. This token should be inserted into the code example below to replace YOURAPIKEY
. You will also need to add an agent username, in place of YOURUSERNAME
in the example code below. Where you see {YOURHELPDESKURL}
, replace that with the URL to your help desk. For example, "https://logiforms.zendesk.com".
Example Code
The example code below shows how to pass form field values to Zendesk to create a new ticket. This example is based on https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#create-ticket
// connect to the API
var client = zendesk.createClient({
token : '{YOURAPIKEY}',
username : '{YOURUSERNAME},
remoteUri : '{YOURHELPDESKURL}/api/v2'
});
var obj = client.tickets;
// get values from the form
var form = {
name: form.getValue('[Name]'),
email:form.getValue('[Email Address]'),
subject: form.getValue('[Subject]'),
requesttype: form.getValue('[Request Type]'),
formurl: form.getValue('[Form URL]'),
body:form.getValue('[Description]'),
}
var ticket ={
"ticket":
{
"requester":
{
"name": form.name,
"email":form.email
},
"subject":form.subject,
"custom_fields": [
{ "id": 20752981, "value": form.requesttype},
{ "id": 20763042, "value": form.formurl}
],
"description": form.body,
"group_id":20928423
}
}
// SEND THE TICKET TO ZENDESK!!!
obj.create(ticket,function(err, req, result) {
if (err){
log(JSON.stringify(err));
log(err.result.toString())
logiforms.endRequest()
}else{
log(JSON.stringify(result));
logiforms.endRequest()
}
});
Getting Custom Field ID's
When mapping fields on your form to custom fields in Zendesk, you'll need to find the custom field ID. To do this. follow the steps listed in this article:
https://support.zendesk.com/hc/en-us/articles/4408832419738-Viewing-your-ticket-fields
Getting the Group ID
If you wish to assign a ticket to a specific group. follow the steps in this article to retreive the group ID. The code above includes the "group_id" attribute for assigning the ticket to a group. You can also remove this attribute, to leave the new ticket unassigned.
Using the Zendesk API
For API details and examples, see the Zendesk API Docs and the the node-zendesk module docs.
0 Comments