Add a Tag to a New ticket if attachment is present

19 Kommentare

  • Brett Bowser
    Zendesk Community Team

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

    2
  • 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!

    0
  • Ash Divay

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

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

    Cheers

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

     

     

     

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

    "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? 
    1
  • 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!

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

     

     

    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

    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: 

    {"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 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?

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

    {"ticket":{"additional_tags":["attachments_no"]}}

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

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

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

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

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.

Powered by Zendesk