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?
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!
One other caveat - this would only work if the filenames are unique.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.