Add a Tag to a New ticket if attachment is present

42 Comments

  • Brett Bowser
    Zendesk Community Manager

    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:

    • Basic Authentication - should this be enabled or disabled? 
    • There are also 3 other options prior to submitting: Test Target, Update Target, Delete Target - which should we select? 
    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:

    {"error":"Unprocessable Entity","message":"Server could not parse JSON"}

    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: 

    {"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 %}

    Example without spaces:

    {"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 %}

    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. 

    • The first thing I would do is remove the liquid code and simply try to send the request without it. That will help you narrow down the issue.
    • Of course, you want to make sure the authentication is working correctly as well. So, that could be something as simple as putting an invalid password/token and see if that gives you a different error.
    • Another thing I might try is to view the output. I usually do this by creating a dummy trigger and copying the code into an email. Then I can activate the trigger and get the output emailed to me where I can reference it. That is also a great way to confirm the liquid code is working as intended. 
    • You could also try and replicate the request from the CLI to give you a quicker and easier to adjust feedback loop. 

    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
  • Alisha Strawbridge

    do you think I can use this exact method for anytime a ticket is updated by an end-user with public comment with attachment ?

    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

Please sign in to leave a comment.

Powered by Zendesk