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:

 

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. Navigate to the Admin Center.

mceclip0.png

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

mceclip0.png

3. Select Settings, then enable Password access and/or 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.

mceclip2.png

 

Create an API token

It is recommended that you use API tokens to keep your agents' passwords safe.

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

mceclip3.png

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

mceclip4.png

 

Create a webhook

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

mceclip1.png

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

mceclip2.png

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.png

4. Select Basic authentication, then input your credentials.

If you created an API token, this is where you would paste it as the password and add /token to the end of your email, otherwise, you can use your normal email and password. In either case, Basic authentication should be selected.

mceclip7.png

 

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.

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

mceclip1.png

2. Select Add trigger.

mceclip2.png

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.png

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

mceclip7.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.

 

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
}
}
}

Was this article helpful?
1 out of 2 found this helpful

Comments

5 comments

  • Exactly the article I was looking for ...... but....

    We're a tiny company, no budget for developers, however do have IT background.  This is my first attempt to work  out how to update both ticket subject and private comment via a trigger.

    Followed the above, but no matter what I do the trigger is not authenticated.  "Couldnt authenticate you"

    (Even if i change the webhook to no authentication)

    Zendesk doco is really lacking in how to setup webhooks and triggers.  This was the best instruction I could find.
    [We dont use SSO]

    In the above example, I would have expected the trigger to pass credentials, to authenticate the request?  At present in the webhook Activity I can see the trigger was called, the correct ticket.id is referenced.

    Failed: 401 Unauthorised.

    Suggestions?

    Thanks, Troy

    0
  • Hi Troy, thanks for your comment.

    I've moved this discussion over to a ticket to better assist you with your inquiry.

    0
  • Thanks Michael - solved with your assistance.  Newbie issue.  As this was my first foray into webhooks I didnt realise I had to "switch on" Zendesk APIs - I just jumped right in to webhook authoring.
    Perhaps consider adding a pre-condition statement to this article.
    Plus your video supplied on establishing API Tokens and their use was very informative - and what we have implemented as a result.
    Appreciated.

    0
  • Michael Emmerson Troy Johnston any chance of sharing the resolution to the 401 issue? 
    I am simply copying one field with another on the same ticket using a webhook but getting the Auth failure.

    {
    "ticket":{
    "custom_fields": [{"id": 360003740658, "value": "{{ticket.ticket_field_360003533717}},"}]
      }
    }

    0
  • Hi James, thanks for your message. Please see the new updates article on how to create this webhook. API access must be enabled for this to work which was the resolution for Troy's 401 issue.

    0

Please sign in to leave a comment.