How to add a tag in Zendesk to a New ticket if attachment is present

I’ve come across this requirement while working with a recent client and I thought I’d share it with you.

Context: avoid forwarding new tickets with attachments to an external receiver.

I not allowed to say which company I am working with, neither which AI tool they are considering using. NDAs amirite? That’s not even important. Let’s dive in.

Bigger context:

Client wants to introduce an AI tool to automate some of their processes for the Chat and Email channels. For Chat they want to serve predefined messages and for email they want to suggest resolutions based on their past data and documentation: Knowledge base and Macros list.

I don’t need to expand on what a big disruptor AI tools are. Whether we like it or not, they are the future.

As any big company, you don’t have the flexibility to just plug something in and see how it works. It’s bad practice to introduce a new tool that can potentially disrupt serving ~ 100K tickets/month and flip your support system upside down. You want to test first.

How do you test introducing a new tool that can potentially save you hundred of thousands of dollars per year? Well, you create a control group to test with.

This is another topic in itself which will require another article. Oh hey, I’ve written that article too. Here it is 🌞

As a disclaimer, Zendesk has also published something similar here.

Moving on with our main topic to avoid forwarding new tickets with attachments to an external receiver.

You want to somehow identify these incoming new tickets that have attachments. As it stands, there is no out of the box way to detect attachments in tickets. Luckily, there is a workaround for this. You can use the Zendesk API to flag incoming tickets with attachments.

Tools needed: Zendesk API, Triggers and Liquid Markup

A quick note if you’re unfamiliar with Liquid Markup, it’s a templating language created by Shopify that works really well with Zendesk. Read more about it here.

Here’s how to do it:

1. Enable API access type (see screenshot)

_Su39914WQWsUXmG-os47Q.png

Password Access item 3 on the screenshot above - if you want to use username and password for your API auth only.

For token select item 4 on the screenshot - if you are going to generate API token in Zendesk and use that.

You don't have to enable both, you can use whichever one is easier for you.

2.Create target extension > HTTP

Title : Check for tickets containing attachment

URL : https://domain.zendesk.com/api/v2/tickets/update_many.json?ids={{ticket.id}}
Method PUT
Content Type JSON

3 Create tager extension > Email target

Title: Forward tickets to external source

Email address: whatever@domain.com

Subject: This ticket {{ticket.id}} has been forwarded to you

4.Create Trigger

Name of trigger: Check for Attachments and add tag
Condition - Ticket is created
Action - Notify Target : Check for tickets containing attachment
JSON Body :

{"ticket":
{% for comment in ticket.public_comments offset:0 limit:1 %}
{% if comment.attachments.size > 0 %}
{"additional_tags":["attachments_yes"]}
{% else %}
{"additional_tags":["attachments_no"]}
{% endif %}
}
{% endfor %}

Above code checks the comment for attachments, and if attachments is more than 0, then it tags the ticket with "attachments_yes"

or else it will tag it as "attachment_no"

NOTE: You will see the following error below which I will encourage you to ignore:

-ppf_33E5Mci7QdBoua_dg.png

‼️ Please note that it’s very important how you copy the above code. Avoid weird hyphens and extra spaces. It will not work if formatting is incorrect.

Also, again, you can ignore that error message, the JSON target is trying to validate your code as JavaScript rather than Liquid.

5. Create trigger

Trigger name: Forward tickets to external

Condition:

  • Ticket is created

  • Ticket contains tag “attachment_no”, does not contain tag “attachment_yes”

Action: Notify target - Forward tickets to external source

And that’s about it. Let me know how it goes and hope this helps.

If it looks complicated, no worries, drop me a line or book a call with me and I can help you.