Recent searches
No recent searches
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 comments
Brett Bowser
Awesome tip Ash! Thanks for taking the time to write this up and share with everyone :)
0
James
Hi, thanks for the advice!
However I am receiving a parse error on line 2:
Expecting 'STRING', '}', got 'undefined'
Any ideas how to fix this? Thanks!
0
Ash
You can ignore that error message, the JSON target is trying to validate your code as JavaScript rather than Liquid.
0
James
Thanks Ash, the trigger doesn't seem to be working still :(.
Please can you confirm all the 'Conditions' and 'Actions' you are setting for the trigger?
Cheers
0
Ash
Hi Alex,
Can you explain what you mean by "doesn't seem to be working"?
You can also check if the trigger is even firing.
If it is then check if the external target is working-check if API logs have any errors.
Let me know.
0
James
Hi Ash,
It says it has triggered, however the tags are not being added to the tickets.
The JSON script in the Trigger settings should add the following tags, correct?
"attachments_yes"
"attachments_no"
Perhaps the issue is with the target extension:
0
Melissa Norton
Hey Alex,
I was having the same issues as you with the trigger firing, but the tags not adding to the ticket. I had a colleague assist and he said I needed the Basic Authentication, which is not mentioned in the article. He had me:
1. Create an API token which we called "Attachment Target" but call it whatever you want. Be sure to save your token somewhere because once you "Save" it, you cannot access it again.
2. We created the target "Attachment Tags" using Ash's instructions above and added Basic Authentication with a system admin address for the Username: admin@ourcompany.com/token
3. Basic Authentication Password: API token that you copied and saved
4. Create Target and Submit
5. Then we created Ash's trigger
Hope that helps you!
0
Ash
@... Thank you,
And yes, you need basic authentication either via API token or admin credentials to do anything with external targets.
Sorry, I assumed everyone knew that.
0
Max McDaniel
Ash, in testing, I'm unable to get the trigger, which is firing successfully, to hit the extension I built.
When I test the extension, I get an error:
Any thoughts?
0
Alejandro Colon
@...
Personally, when using liquid to create my JSON requests, I have had to remove all extraneous spaces to get the JSON to parse correctly.
Example with spaces:
Example without spaces:
I would try that as a troubleshooting step.
0
Max McDaniel
Thanks @..., I tried copy/pasting the example you shared but received the same error.
Is there something in the actual JSON that I need to be changing/adding?
Based on the error, I don't suspect this is an authentication issue, but could that be the case?
0
Alejandro Colon
I personally have not implemented the code in this post but I saw your issue and I know I have had a similar issue in the past.
Potentially your issue could be related to authentication but it also could be a number of things. I would start at the basics and get something working and then start from there.
That should help you narrow down the issue.
0
Max McDaniel
Thanks @..., was able to confirm that it doesn't appear to be an auth issue, as changing the credentials caused a different error. I'm not familiar with JSON/Liquid so not sure what would be a basic request to run, but when I left the JSON input blank it errored out with "400 Bad Request" ("both ticket IDs and arguments required").
I created a trigger to send the liquid script via email and it (I think correctly) delivered this for a ticket which did not have an attachment:
{"ticket":{"additional_tags":["attachments_no"]}}
What I don't know is how that translates into adding a tag to the ticket.
0
James
After following Melissa's post i've managed to get it working. Thanks a lot!
The JSON body that Ash posted originally worked fine for me.
0
Alejandro Colon
@...
Now, that you have ruled out authentication as the issue and it seems like the liquid code is producing the appropriate request. The next thing I would do is take the output you received and send that in the original request. That will allow you to confirm that the endpoint is receiving the appropriate content. If that does not work then it has something to do with the target since you have verified that the liquid code is producing the appropriate request and that authentication is not an issue.
This is the documentation on what endpoint to hit and what it is expecting. Which, it seems, aligns with Ash's post.
https://developer.zendesk.com/rest_api/docs/support/tickets#updating-tag-lists
-----------------------------------
As a sidenote, it is interesting that the error is not an authentication error but it may be the correct error. I am not sure.
-----------------------------------
If you don't mind, take a screenshot of the target you created and the trigger.
Feel free to scrub out your company name in the URL but leave the rest as that is critical.
0
Jack S. Edwards
not sure if anyone is still having difficulty but if so remember that in your target creation you need to do this as an example:
Username: steve@abccompany.com/token (so the email address with "/token"
Password: jghekrghoierhgoiejfgiodjfoidjoidjiodjvoi (the API token you generated)
I was having trouble until I realized the format
0
seemabali kamboh
If you don't mind, take a screenshot of the target you created and the trigger. Feel free to delete your company name in the URL but leave the rest as it is crucial.
0
Giro Po
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.
0
Terry Ehrhard
I find this very useful since we need to know about attachments the moment the ticket arrives (hint hint wink wink - Zendesk team why isn't this field within core Ticket API results....?). One thing I noticed is occasionally we get the following error and wondering if anyone else experienced this issue. And if so, how was or could this be fixed?
Seems to only happen every so often yet sometimes I see groups of tickets in a short period where this occurs and worried this extension may fail as we continue to add new groups.
{
"error": "ParameterMissing",
"description": "Parameter Both ticket ids and arguments must be present is required"
}
0
WhatsApp Connector
Hello,
In case you are looking for a feature that add tags depending on the presence or lack of attachments, we have published the following app in the marketplace. On top of that, it also establishes them depending on the file extension (ri_application/pdf, ri_application/docx, ri_application/jpg, etc.)
https://www.zendesk.com/apps/support/respira-tag-files/
0
Dean Kongslie
@... I am getting the same errors that @... was receiving.
Separately, using your guide I tried to do something a little different. Any idea why this does not work?
{"ticket":
{% for comment in ticket.public_comments %}
{% if comment.attachments.file_name contains ".ics" %}
{"additional_tags":["attachments_ics"]}
{% endif %}
}
{% endfor %}
0
Terry Ehrhard
This is what we are now using which works well. We found a bug in expecting that attachments are only in public comments and now utilize searching all comments for any attachments
{"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
Dean Kongslie
Thanks @... that's helpful.
Do you know if there is any reason to believe that the code below would not work?
{"ticket":
{% for comment in ticket.comments offset:0 limit:1 %}
{% if comment.attachments.size > 0 and comment.attachments.file_name contains ".ics" %}
{"additional_tags":["attachments_ics_yes"]}
{% else %}
{"additional_tags":["attachments_ics_no"]}
{% endif %}
}
{% endfor %}
0
Terry Ehrhard
50k executions in the last week - only one failure due to a timeout. I would say it is working well
0
Ash
I am happy to see this code worked for so many of you.
Please feel free to contact me if you need any free advice on a solution.
0
Kuldeep Patidar
Hi Ash, I hope you are doing well!
I have a query regarding ticket event properties! I was wondering if there is a functionality/capability within Zendesk to automatically trigger an escalations after 'X' amount of comments or events per ticket.
For example: A Zendesk ticket is submitted by the client, the client is provided guidance by the Core agents via macros and the client does not understand the request, they are then sent to Tier 2 for clarification, and Tier 2 comes back into the Zendesk ticket with questions for the Core Agent. This goes on to hit 10 events/comments on the ticket.
Would it be possible to have the 10th comment trigger an automatic escalation, or apply a tag that could be routed to a separate queue?
I'm not certain if we can set it with the help of the HTTP target. Any information that you could share would be greatly appreciated.
Kind Regards,
Kuldeep
0
Terry Ehrhard
Hi @... - This is easily accomplished within a trigger. We have one in place that elevates to high priority when 8 replies are exceeded
0
Kuldeep Patidar
Hi @...,
Thanks for sharing the great workaround! This looks very much similar to what I thought, but I would like to know if 'Agent Replies' condition will address the 'Internal comments' or not?
Since we're using an escalation mechanism to compete with those request and with the increase in back and forth between the teams, we're getting a lots of internal comments in the ticket and therefore want to apply a tag that could be routed to a separate queue if feasible. Or if there is any other workaround, please let me know.
Thanks again!
Kuldeep
0
Terry Ehrhard
Hi Kuldeep - This would give you a count of any/all replies by agents both to customer and to internal agents. See this article https://support.zendesk.com/hc/en-us/articles/115015611647-Trigger-conditions-and-actions-reference
If you only wanted to determine internal comments I suppose you could use markup to count the number of internal comments and add a tag when the count exceeds your preset limit.
0
Kuldeep Patidar
Hi @...,
Thanks for confirming. I feel strongly about information and love learning more on this. If possible, can you please help me in building that markup to achieve my goal.
Edit: I think we need to use “tickets/update_many” endpoint here.
I'm afraid as I have minimum knowledge of markup, so not sure how the correct code/request should look like.
I truly appreciate your valuable support!!
Regards.
Kuldeep
0