Add a Tag to a New ticket if attachment is present



Posted Dec 02, 2020

To tag new tickets with a tags when they have attachments.

Use Case :

You can then use this tag to filter tickets with attachments to one view while other with no attachments to another view.

There can be other use cases too. 

Steps:

1. Enable API access type (see screenshot)

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 but one will do.

2.Create target extension > HTTP
Title : Update Tags

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

Make sure your external target uses Basic auth. either via API token or admin credentials.

 

3.Create Trigger
SET-Check for Attachments
Condition - Ticket is created
Action - Notify Target : Update Tags
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, if attachments more than 0 than it tags the ticket with "attachments_yes"

or else it will tag as "attachment_no"

NOTE: You will see the following error-

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

I tested this and it works for all new tickets

If this was helpful please upvote this and feel free to drop me a line on Linkedin.


1

46

46 comments

Hi Tipene,

 

I ran this just for short period of time and got one email with attachment where the ticket was correctly tagged with ‘’attachments_yes''.

 

Here is the webhook: 

 

And this is the attached trigger:

 

 

Regards,

Rose

0


Thanks for the update, Rose!
 
Can you send me through a screenshot of your webhook set up, including the JSON body containing the markup? And just to be double sure, this is working with tickets other than chat, correct?
 
Thanks!
 
Tipene

0


Hi 1264158211509 ,

 

We use Agent Workspace but we haven't switched to messaging yet and we are still using the live chat option. 

Here is an example of what is happening:

Regards,

Rose

0


Hi Rositsa,
 
Nothing immediately comes to mind that would cause this workflow to function incorrectly with live chat; the attachments should be available to the API in the same way as normal tickets. 
 
Are you using messaging by any chance? If so, that would likely be the cause of what you're seeing.

0


Hi, 

 

Can you advise if this is an issue that anyone else is experiencing as well?

I was able to create webhook and trigger as shown above, but the issue that I am experiencing is that when a file is sent through Live chat, it seems like Zendesk doesn't consider that as ‘’attachment''. I tested that couple of times and when I check in the ‘Attachment Manager’ App, it says that there are no attachments, when a picture was uploaded via chat. 

 

All of the chat tickets (even those with pictures in them) are being tagged with attachements_no. 

 

Is there probably something that I am doing wrong?

 

Regards,

Rose

0


Hey 1263169163590,

As per another suggestion here, changing ticket.comments to ticket.public_comments may work for you here. The second line would look like this:

{% for comment in ticket.public_comments offset:0 limit:1 %}

0


1263169207570 1263169159570

This was woking fine for us, but it stopped and I've been unable to get it working again.  I'm using a target with a basic authenticion using token.  I know that the authentication is working fine b/c I've tested it without the liquid markup and it updates the ticket (I'm using the update many endpoint).

Something is off with the code. I keep getting the unable to parse json error.  I've tried copying as a single line, multiline. Not sure if Zendesk changed something.  

 

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

 

 

0


Hi Alon, 

I created a ticket on your behalf. Don't worry! one of our colleagues will get in touch with you regarding this issue.

0


1263169159570 (or anyone else who is knowledgeable) - I could use some assistance with this.

 

I set up my webhook and trigger according to all the comments. The trigger is firing as it should, but every ticket is getting tagged as if it has an attachment. Any idea why that may be? 

0


Hi Fabio,

1263169159570 might want to jump in here to offer more clarification but from my understanding of how this is written, you're correct that the offset:0 and limit:1 specifies that only the most recent ticket comment will be evaluated against. You can increase the limit to evaluate against more comments in the ticket.public_comments array. 

The next line is evaluating the actual size of the attachment, not the attachment count on that ticket comment so for you to be able to check if there are multiple attachments, you will need to implement some type of counter to track how many attachments are present on the ticket, and apply the tag depending on that. 

Here's a link to the docs which might be helpful to you:

https://shopify.github.io/liquid/tags/control-flow/

I hope this helps!

Tipene

0


Sign in to leave a comment.

Didn't find what you're looking for?

New post