How I can send attachment along with comment to Jira using Jira Rest API V3

In V2 version, if I need to include the attachment in the comment, I need the payload like this
{
“body”: “Here is a link to the [^file.pdf] file.”
}

But for v3 since the payload changed, I have to use somethings like this:

{
    "body": {
        "version": 1,
        "type": "doc",
        "content": [
            {
                "type": "paragraph",
                "content": [
                    {
                        "type": "text",
                        "text": "Here is a link to the [^file.pdf] file."
                        
                    }
                ]
            }
        ]
    }
}

And it does not work (not show the file inside the comment)
Is there anyway we can make the attachment in the comment body of V3 work like V2

2 Likes

Hello @Quan

If you use the GUI to add an attachment to an existing Issue’s comment, then use the v3 REST API to GET and inspect that comment’s ADF structure, you’ll see it’s nothing like that.

It will be something like:

{
    "body": {
        "version": 1,
        "type": "doc",
        "content": [
            {
                 "type": "paragraph",
                 "content": [
                     {
                         "type": "text",
                         "text": "Here is the file"
                     }
                 ]
             },
            {
                "type": "media",
                "attrs": {
                       "type" : "file",
                       "id": "6e7c7f2c-dd7a-499c-bceb-6f32bfbf32b5",
                       "collection" : ""
                }
            }
        ]
    }
}

The media and mediaGroup node types are described in the ADF documentation.

If in doubt, inspect real ADF examples. It’s much more productive than guessing how ADF works.

Hi @sunnyape Thanks for your answer!
You are correct, I inspected and debugged to find out that is media Id. But the real issue is how to get that id “6e7c7f2c-dd7a-499c-bceb-6f32bfbf32b5”, the attachment metadata only return s.t like this:

[
    {
        "self": "https://domain.com/api/3/attachment/134612",
        "id": "12345",
        "filename": "file.xlsx",
        "author": {
            "self": "",
            "accountId": "accountId",
            "emailAddress": "test@test.com",
            "avatarUrls": {
                "48x48": "",
                "24x24": "",
                "16x16": "",
                "32x32": ""
            },
            "displayName": "Jira Integration",
            "active": true,
            "timeZone": "America/Los_Angeles",
            "accountType": "atlassian"
        },
        "created": "2023-09-29T14:47:38.963-0700",
        "size": 105631,
        "mimeType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        "content": "https://domain.com/rest/api/3/attachment/content/134612"
    }
]

I tried to read the document but found no way to get it

1 Like

Ahh, well, now I have the bad news for you. That id of that attachment needs to be looked up via the ‘Media API’, as per the ADF documentation:

Attributes

  • id is the Media Services ID and is used for querying the media services API to retrieve metadata, such as, filename. Consumers of the document should always fetch fresh metadata using the Media API.

BUT… Atlassian don’t allow public access to that API, as per this thread, so you can’t get that id.

HOWEVER… there are some workarounds, as per this thread.

This is one of those ‘catch 22’ situations with the v3 REST API and ADF where you can’t achieve the outcome described in the documentation, and where it’s better to use the v2 REST API until all the issues with v3 and ADF are sorted out.

2 Likes

Thanks so much @sunnyape for your response! I appreciate your help!

1 Like

Thanks @sunnyape This is still an issue in 2024.
Could some one suggest how are doing with v2 version?

1 Like