Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Use the REST Api to pull COMMENT attachments from an issue

Fabian Dittrich
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 12, 2024

Pulling regular attachments attached directly to an issue is no problem. 

When parsing comments though, this is how comment attachments are returned by the API:

____

"body"=>

  {"type"=>"doc",

   "version"=>1,

   "content"=>

    [{"type"=>"paragraph", "content"=>[{"type"=>"text", "text"=>"Hi ABC,"}]},

     {"type"=>"paragraph",

      "content"=>

       [{"type"=>"text",

         "text"=>

          "TEXT ABC?"}]},

     {"type"=>"mediaSingle",

      "content"=>[{"type"=>"media", "attrs"=>{"type"=>"file", "id"=>"5ac80cf3-82b7-4f59-a015-09dcbc3f18de", "collection"=>"", "width"=>2534, "height"=>266}}],

      "attrs"=>{"layout"=>"align-start"}},

     {"type"=>"paragraph", "content"=>[{"type"=>"text", "text"=>"Many thanks"}]}]},

 

___

Only the bold id 5ac80cf3-82b7-4f59-a015-09dcbc3f18de is returned, no filename, no URL and there seems to be no way to access an attachment with the above ID.

 

How can I get more info from the API about comment attachments?

 

 

1 answer

0 votes
Hariharan Iyer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 12, 2024

Hi @Fabian Dittrich ,

 

There doesn't seem to be a way to do this using the v3 API. However with the v2 API it seems possible, albeit in a convoluted way. e.g. with this URL

'https://xxxx.yyyyy.net/rest/api/2/issue/zzz-9?fields=comment,attachment'

I get the following (output snipped for brevity)

"fields": {
"attachment": [
{
"self": "https://xxxx.yyyy.net/rest/api/2/attachment/10000",
"id": "10000",
"filename": "Screenshot 2024-02-07 at 9.02.56 PM.png",
...
"comment": {
"comments": [
{
"self": "https://xxxx.yyyy.net/rest/api/2/issue/10030/comment/10017",
...
"body": "!Screenshot 2024-02-07 at 9.02.56 PM.png|width=1248,height=727!\n\ntesting attachment",

 Now you can correlate the content in body with the filename in attachment  and use the url in the self field therein to download the actual attachment.

 

I know it's not the cleanest approach, but seems like the best we can do with what's available.

 

Hope that helps!

Hariharan Iyer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 12, 2024

One other caveat - this would only work if the filenames are unique.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events