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

 

2. Create an API token

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

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.

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

 

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

Was this article helpful?
6 out of 7 found this helpful

Comments

10 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
  • Hi! I have done everything that this article says (not from the article, but before - looking at Zendesk API Reference), but it won't work. The reason why I found this page was that I tried and search for someone else with the same issue. Looking carefully through the article, it seems that I have done everything the exact same way. Testing webhook goes through OK and ticket is updated (testing done from Admin center, webhook). 

    I have pasted in one of your JSON's as well. Doesn't work. 

    When I update through Postman, it work's. 

    Can you help? 

    Also: the username and password changes everytime I click Edit on the webhook - is that normal (i have to add /token and token key each time)?

    0
  • Hi Kristian, Thanks for your message. Note that without seeing all of your settings it will not be possible for us to be able to troubleshoot this. If you send an email to support@sweethawk.com that contains a screencast showing 1) all of the webhook settings (including the 'Activity log'), 2) Your API settings, 3) the trigger settings that fires the webhook and 4) the events log of a ticket in which the trigger was fired, it may be possible for us to make some suggestions here. 

    0
  • Thanks, Peter Godden!

    0
  • Hello,

    Is there any way to update the requester of a ticket using the email address/user id of whomever is in the CC field?

    We have a system that automatically sends order confirmations to our customers and our support email address, the problem is that they come into Zendesk our support address as the requester every time, we have to manually change it for each ticket.

    I've been able to successfully up date the "requester_id" when the value is manually typed in JSON string, but anytime I try to use the variable field of "collaborators_ids" it doesn't do anything.

    Thanks for any help!

    0
  • Hi Lucus,

    I was able to achieve this by using liquid markup in order to pull out certain elements of the CCs. For example:

    {% for cc in ticket.ccs %}{{cc.name}}({{cc.email}}){{cc.id}}{% endfor %}

    You could reduce this down to the id to update the requester as seen below in the final JSON.

    {
      "ticket": {
        "requester_id": {% for cc in ticket.ccs %}{{cc.id}}{% endfor %}
      }
    }

    I hope this helps!

    0

Please sign in to leave a comment.