Add a Tag to a New ticket if attachment is present

21 Comentários

  • Brett Bowser
    Zendesk Community Team

    Awesome tip Ash! Thanks for taking the time to write this up and share with everyone :) 

  • alex

    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!

  • Ash Divay

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

  • alex

    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? 


  • Ash Divay

    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.




  • alex

    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? 



    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? 
  • 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: 

    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!

  • Ash Divay

    Melissa Norton 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.



  • 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?

  • Alejandro Colon

    Max McDaniel

    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: 

    {% for comment in ticket.public_comments offset:0 limit:1 %}
    {% if comment.attachments.size > 0 %}
    {% else %}
    {% 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.

  • Max McDaniel

    Thanks Alejandro Colon, 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?

  • 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.


  • Max McDaniel

    Thanks Alejandro Colon, 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: 


    What I don't know is how that translates into adding a tag to the ticket. 

  • alex

    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. 

  • Alejandro Colon

    Max McDaniel

    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.


    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.

  • 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 ?

  • Jack 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: (so the email address with "/token"

    Password: jghekrghoierhgoiejfgiodjfoidjoidjiodjvoi (the API token you generated)

    I was having trouble until I realized the format

  • 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.

  • 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.

  • 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"

  • Guillermo - CX Lead


    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.)


Por favor, entrar para comentar.

Powered by Zendesk