How to create a webhook to make any change to a ticket. (advanced)

This article will cover how to change ticket data within Zendesk that normally wouldn't be possible via a trigger or automation. This can be useful if you would like to:

  • Automatically add a public/internal comment to a ticket.
  • Updating the contents of text, multi-line, numeric and regex ticket fields.
  • Changing the subject line of a ticket.
  • Add Collaborators/CC's to a ticket.

The process involves two parts. The first is creating a webhook that will push data into the ticket and the second is creating a trigger that contains the data you wish to push to the ticket. If you've already created the webhook, you can skip to part 2.

 

This article contains the following sections:

 

1. Enable API

The first step for creating a webhook is to ensure you have enabled API access which is required in order to get a successful authentication.

1.1 Navigate to the Admin Center.

mceclip0.png

1.2. Select Apps and integrations, then select Zendesk API.

mceclip0.png

1.3. Select Settings, then enable Token access.

If this is your first time using the Zendesk API, you may be prompted to accept the terms and conditions before this page is visible.

 

2. Create an API token

2.1. From the same screen, select Add API token.

mceclip3.png

2.2. Select Copy so that you can use this as the password within the next step, then select Save.

mceclip4.png

 

3. Create a webhook

3.1. From the Admin Center, select Apps and integrations, then select Webhooks.

mceclip1.png

3.2. Select Actions, then from the drop-down menu, select Create webhook.

mceclip2.png

3.3. Input the following configuration:

UI Element Input
Name Update ticket
Description A webhook for updating a ticket. (optional)
Endpoint URL https://YOURSUBDOMAIN.zendesk.com/api/v2/tickets/{{ticket.id}}.json
Request method PUT
Request format JSON

mceclip0-1.png

3.4. Select Basic authentication, then input your credentials.

With the API token you created in step 2, this is where you paste it as the password and add /token to the end of your email for the username. Basic authentication should be selected as the authentication type.

mceclip7.png

 

4. Create a trigger

Now that we've successfully created a webhook that determines where the data will be pushed – in this case it is the current ticket – we need to create a trigger that will decide when this occurs and what data will be updated on the ticket.

4.1. From the Admin Center, select Objects and rules, then select Triggers under Business rules.

mceclip1.png

4.2. Select Add trigger.

mceclip2-1.png

4.3. Input a Trigger name and Description relevant to what you're updating on the ticket followed by the Conditions for when you would like the update to occur.

mceclip4-1.png

4.4. Select Add action, then select Notify active webhook and finally, select Update ticket which we created in the previous section.

mceclip7-1.png

 

It is very important that you add a nullifying condition to your trigger for this type of action (webhook). Since the trigger is causing the ticket to update itself, the consequence of it not being nullified means that the ticket will update itself hundreds (if not thousands) of times a minute until the trigger is manually disabled.

 

5. Input JSON body

You can now configure what changes should occur to the ticket when the trigger fires by inputting the JSON body.

mceclip0.png

Below are a few examples of what you can do. For more information on setting things on a ticket using the Zendesk API see this article

 

Make a public comment: 

{
"ticket": {
"comment": {
"body": "This a public ticket update regarding ticket {{ticket.id}}.",
"public": true
}
}
}


Make a private comment: 

{
"ticket": {
"comment": {
"body": "This a private ticket update regarding ticket {{ticket.id}}.",
"public": false
}
}
}


Change the subject line: 

{
"ticket": {
"subject": {"My printer is on fire"}
}
}

 

Setting custom ticket fields:

{
"ticket": {
"custom_fields": [{"id": 45844587, "value":"09:00"},{"id": 45844607, "value":"Melbourne"},{"id": 45844547, "value":"Support (1022)"},{"id": 45844627, "value":"60"}]
}
}

 

Add CCs: 

{
"ticket": {
"email_ccs": [{"user_email": "zendeskagent1@gmail.com", "user_email": "zendeskdemonstration@gmail.com", "action": "put"
}],
"comment": {
"body": "This is an email notification regarding ticket {{ticket.id}} regarding {{ticket.subject}}. Here's what it's about - {{ticket.description}} ",
"public": true
}
}
}

 

Need Help?

Consider reaching out to a Zendesk implementation partner for professional advice and recommendations relating to the user of webhooks and your workflow.

If you're struggling with liquid markup, consider the following resources:

  1. Shopify Liquid Syntax Library
  2. Install our free Liquid Placeholder app to easily test liquid markup.

Was this article helpful?
20 out of 21 found this helpful