Zendesk > Jira: Attachments.created missing?

Originally asked by Hannu Turunen on 15 March 2021 (original question)


Hi.

I’m trying to merge last/latest comment & all the attachments on that comment from ZD to JIRA. For that I think I need the attachment created timestamp so I can compare that to comment timestamp.

Or is there a better way to catch all the attachments of a single comment?

Looking at JIRA remote replica, I can’t find attachment created timestamp.

According to https://docs.idalko.com/exalate/display/ED/Attachments should there be a timestamp?

Here’s the JIRA remote replica attachments & comments from ZD:

{
“version”: {
“major”: 1,
“minor”: 15,
“patch”: 0
},

“hubIssue”: {
“components”: ,
attachments”: [
{
“id”: “369197845598”,
“mimetype”: “image/png”,
“filename”: “inline-453156139.png”,
“filesize”: 927,
“internal”: false,
“zip”: false
},
{
“id”: “369242875237”,
“mimetype”: “image/png”,
“filename”: “image.png”,
“filesize”: 4009,
“internal”: true,
“zip”: false
},
{
“id”: “369242886377”,
“mimetype”: “text/plain”,
“filename”: “test.txt”,
“filesize”: 58080,
“internal”: true,
“zip”: false
},
{
“id”: “369197873058”,
“mimetype”: “image/png”,
“filename”: “image.png”,
“filesize”: 1762,
“internal”: true,
“zip”: false
}
],

“description”: “test”,
“watchers”: ,
“fixVersions”: ,
“key”: “860”,
“summary”: “testing 4.5”,
comments”: [
{
“id”: “782263108038”,
“author”: {
“key”: “398349362114”,
“active”: false,
“email”: “xxx”,
“displayName”: “xxx”,
“username”: “xxx”
},
“body”: “xxx”,
“created”: 1614775537000,
“internal”: true,
“restrictSync”: false
},
{
“id”: “782263552298”,
“author”: {
“key”: “398349362114”,
“active”: false,
“email”: “xxx”,
“displayName”: “xxx”,
“username”: “xxx”
},
“body”: “xxx2”,
“created”: 1614775574000,
“internal”: true,
“restrictSync”: false
}
],


Comments:

Francis Martens (Exalate) commented on 16 March 2021

It is a bit unclear what exactly you would like to achieve.
Send over all the attachments contained in a comment?

Hannu Turunen commented on 16 March 2021

Hi.

Yes, just the latest comment and all the attachments contained on it.

ZD agents might do internal commenting/notes before escalating to JIRA and we don’t want those comments & attachments to JIRA. Just the last comment & all the attachements on that comment.

I can successfully take the last comment and last attachment but if the last comment contains 2+ attachments, I can’t tell which attachment is linked to last comment.

Francis Martens (Exalate) commented on 26 March 2021

An approach would be to scan the last comment for attachments and add these attachments to the replica?

Answer by Francis Martens (Exalate) on 22 May 2021

Hannu Turunen

Found some time to work on this one.
Following snippet will add to the replica only the attachments which are mentioned in a comment

Outgoing Sync | Zendesk side

// commentFiles is used to collect all the filenames mentioned in comments
//

def commentFiles = []

issue.comments.each { 
    comment ->

    // the regexp is used to fetch the name of a file mentioned in a zendesk ticket comment
    // THis is something like 
    // ![](https://d3v-peter.zendesk.com/attachments/token/EfCbLqeb9gmdox1IS4PFL20Yh/?name=AzureDevOps-Jira.png)
    def matcher = comment.body =~ /!\[\]\(\S+?name=(\S+)\)/
    matcher.each {
        commentFiles.add(it[1])
    }
}

// only send the attachments which have been mentioned in a comment
replica.attachments = issue.attachments.findAll { commentFiles.contains(it.filename) }




The snippet can also be found here.
It should be self explanatory


Hi!

I also have the same problem, I cannot identify which attachments were added together with the latest comment on Zendesk.

In my case the attachments are NOT inline attachments, but added during the comment creation, and they appear inside the comment box under the comment text in the Zendesk UI.

So the comment body does NOT contain anything about the attached file (no ![](https://.zendesk.com/attachments/token/EfCbLqeb9gmdox1IS4PFL20Yh/?name=.png or anything like this*)*, body is only the simple text added by the commenter.

So I would either need a created property of attachments (which is not there at all), or some other property to have the reference between comments and attachments.

There is an attachmentsTokens property of the comments (besides id, author, body, created, internal and restrictSync) , however it is always empty (no value). What is the purpose of attachmentsTokens?