Link or Reference an Attachment in a Comment

jira-service-desk
jira-cloud
rest-api

#1

I am trying to make a comment on an issue through the Rest API that references or links to an attachment inside that issue. I have already successfully attached a PDF file to the issue and now would like to reference that attachment in a comment using the API so that the Service Desk Customer can access the PDF.

Per the API Documentation on Add Comment the body needs to be:

body
anything
The comment text in Atlassian Document Format.

Looking at the Document Format the only option I see is creating a link to the attachment. But when I use the direct link to the attachment the customer doesn’t have access to that link. Is there a different way of doing this?

Thanks!


#2

I have done some testing and checking of what happens when a comment is made with a reference to the attachment within the UI and it looks like the link to the document is:

https://{domain}.atlassian.net/servicedesk/customershim/secure/attachment/10111/10111_repair_request_TS-44.pdf?fromIssue=10134

and the link from the comment created through the API is

https://{domain}.atlassian.netservicedesk/customershim/secure/attachment/10111/repair_request_TS-44.pdf?fromIssue=10134

They are really close, but when looking at the Comments through the API I get this:

[^repair_request_TS-44.pdf]

and

[repair_request_TS-44.pdf|https://{domain}.atlassian.net/secure/attachment/10111/repair_request_TS-44.pdf]

Another interesting thing is that after I made the comment in the UI and referenced the same attachment, then both links work in either comment. Before that I received a 403 Unauthorized error when clicking the link from the comment created by the API.


#3

I figured out how to do this. Instead of using the Jira API use the Jira Service Desk API. Under request, there is a Create Attachment function that allows you to create an attachment to the issue and then leave a comment for the customer referencing that attachment.

This worked well and I was able to attach a PDF to the issue and then leave a comment for the customer about that PDF.