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?
19 out of 20 found this helpful

Comments

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

    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
  • Hey! I'm back. First of all: thank you for helping me out back in July 2022. For everyone reading - it works now. SweetHawk where able to help me.

    I have another question for you guys over at SweetHawk. What do you think of the robustness of making such a setup like this? Thinking about Zendesk' own view on it in this article.

    I'm just wondering if you think it's robust enough to use in an advanced workflow and to be sure that that workflow will run smoothly.

    Currently I'm building such a workflow, and everything is working fine. But just wanted to get your opinion on this subject.

    0
  • Hi Kristian Tungland, glad everything is working as expected now and thanks for your question. It is true that there are risks when setting up webhooks so that tickets can update themselves. For example if you were to create a trigger without setting a nullifying condition this would cause a loop (which would be bad), or if other updates were happening at the same time, there is a chance the 'race condition' issue noted in the article you linked may come into play. So this is certainly not an ideal solution and you should take the article's recommendation into consideration. Zendesk has made it clear that this type of setup is unsupported, but ultimately this article is outlining a potential workaround for things that might not otherwise be possible, so it really comes down to what works for your needs. It is important that any workflow you setup is tested thoroughly and if you were to notice any problems, depending on the nature of the problem, you may need to consider alternative, more costly approaches. If you would like to discuss this further feel free to email us at support@sweethawk.com

    0
  • Hi All

    I am trying to move data from an organization drop-down field to a ticket drop-down field. This is the JSON i am using:

    {
    "ticket": {
    "custom_fields": [{"id": 10858566133021,"value": "{{ticket.organization.custom_fields.10487074663325.title}}"}]
                    }
    }

     

    When I send a ticket to trigger the  Webhook it returns the below.

    {
        "ticket": {
            "custom_fields": [
                {
                    "id": 10858566133021,
                    "value": ""
                }
            ]
        }
    }

     

    I am bit lost now, any help would be appreciated 

    0
  • Hi Zac, I'm moving this one over to a ticket since it's difficult to answer this in one response.

    0
  • Hi

    Great article. I have used it to send notifications based on language.

    I am looking to use the exact webhook to change assignee based on a value in one of my custom fields

    Is there an option to use an if/else condition in the webhook JSON to achieve it.

    I would like to have something like:

    if custom field value == "value 1"

    {

    assign the ticket to Agent 

    }

    elseif custom field value == "value 2"

    {

    assign the ticket to Agent 2

    }

    else

    {

    Assign ticket to Agent 3

    }

     

    any ideas of how would the syntax look like?

    thank

    Yoram

    0
  • Hi Yoram, Zendesk uses liquid markup made by Shopify and has a library of syntax on their website if you wish to learn more. https://shopify.github.io/liquid/tags/control-flow/

    0
  • Hi,

    I am really looking forward to getting this to work, but in my first attempt it didn't stick, maybe you can help me find out what's wrong. Check out my JSON below:
    {
    "ticket": {
    "custom_fields": [{"id": 1500012216001, "value": "{{ticket.title | split: \"|\" | last }}" }]
    }
    }

    The idea is to get the last portion of the ticket subject line to populate into my custom text field based on the pipe divider. There have been two tickets that have met the criteria so far and they have both failed to populate anything in that field. Also, the custom field was conditional on a selection of a different custom field, so I've gone ahead and removed that condition so it is always visible. Not sure if that matters or not. 

    Let me know if my JSON looks ok to you or if there is anything else you would think to try.

    Thanks!

    Josh

    0
  • Hi Josh, If I can offer a suggestion - try installing our free liquid placeholder app. You'll save yourself heaps of time by testing the liquid markup placeholder by itself without involving triggers, webhooks, and JSON. It's difficult for us to provide advice when there's so much information and variables. Being able to isolate the issue to the placeholder will make it much easier for you to troubleshoot the problem. If you haven't already, check out the Shopify page on 'last' filters. https://shopify.github.io/liquid/filters/last/

    0
  • Thanks Michael!!!

    0

Please sign in to leave a comment.