Recent searches


No recent searches

Attachments in latest_comment placeholder

Answered


Posted Mar 03, 2023

Hi,

I'm integrating to our internal system and need attachments to be available too. I've been trying to work on with latest_comment placeholders but seems that if I have multiple attachment on tickets, data in theplaceholder comes like this:

Attachments:\n6245280-1.pdf - https://karkkainen1546515205.zendesk.com/attachments/token/np1tLW78shen2Mx1dFHDBLxuF/?name=6245280-1.pdf6245280-2.pdf - https://karkkainen1546515205.zendesk.com/attachments/token/4x2Ot7BwZfdYTAn1hvG4XehrE/?name=6245280-2.pdf

Seems that attachments are available only in latest_comment_html and latest_comment_formatted. So what I do now in integration layer, I pick up the string after Attachments: text and then parse it to substrings where there is separated attachment name and attachment URL but when there is multiple attachments, there is no characters between first URL and second attachment name. Is there any workaround that I could separate those and format it as <a href=URL>Name</a>? Originally I assumed that there's a linebreak \n but actually it is not there.

Br.
Otto


0

2

2 comments

image avatar

Remi

Zendesk Customer Care

Hello Otto Lindqvist,

Thank you for your post here, I hope you are doing well today!

In order to achieve what you want to do and pass attachments toward an endpoint via JSON, I wouldn't suggest using the following placeholders with your context/scenario : 

  • latest_comment_html
  • latest_comment_formatted


As indeed, the files / links will be separated by hyphens and no break line, for instance.

I would recommend using the Ticket.Comment object and Comment.Attachments child-node as explained here > Using Liquid markup to customize the formatting and placement of text in comments and email notifications

This placeholders are part of our documentation as well : Standard comment placeholders

I ran a quick test to show you this with a HookBin and here is my Trigger JSON body : 
{
{% for comment in ticket.comments limit:1 offset:0 %}
   {% for attachment in comment.attachments %}
   
   "attachmentName" : "{{attachment.filename}}"
   "attachmentURL" : "{{attachment.url}}"
   
   
   {% endfor %}
    {% endfor %}
}

And here is the Raw JSON that I received : 

This will allow you to pull any property's value in an easier way where you just have to query each node / access each attribute's value within the responded object.

With this placeholder, it will be easier to handle the response as it gives you more granularity coupled with some Liquid Markup condition.

 

Hope this helps! Have a great rest of your day.

Best regards,

2


Thanks for the tips. This definately helped me forward. In order to get valid json array, I had to do a quick if statement inside the loop. 

Here's the code working for me if someone else is interested in the same topic.

"attachments":[
        {% for comment in ticket.comments limit:1 offset:0 %}
           {% for attachment in comment.attachments %}
        {% if forloop.last %}
           {
            "attachmentName":"{{attachment.filename}}",
               "attachmentURL":"{{attachment.url}}"
        }
        {% else %}
        {
            "attachmentName":"{{attachment.filename}}",
               "attachmentURL":"{{attachment.url}}"
        },
        {% endif %}
   {% endfor %}
    {% endfor %}
    ]

Something that did throw me off, was json editor in Zendesk is noting an error on the line where liquid statement starts but it can be ignored.

2


Please sign in to leave a comment.

Didn't find what you're looking for?

New post