When saving a comment with an attachment,please provide the proper payload and how to resolve issue?
Asked by Laxman Khokhar:

API : yourdomain/3/issue/abc-123/comment

{ "body": { "type": "doc", "version": 1, "content": \[ { "type": "paragraph", "content": \[ { "text": "test comment with attchment", "type": "text" } \] }, { "type": "mediaSingle", "attrs": { "layout": "center" }, "content": \[ { "type": "media", "attrs": { "id": "113562", "type": "file", "collection": "attachment" } } \] } \] } }

"{\\"errorMessages\\":\[\\"ATTACHMENT_VALIDATION_ERROR\\"\],\\"errors\\":{}}"

issue/{issueId}/comment


Answers:
author: Sadiq Satriya
body: Hi [@Laxman Khokhar](/t5/user/viewprofilepage/user-id/5556096) ,

The payload structure is correct, but the catch here is that the attachment ID it requires is not what we expect - this ID needs to be looked up via the Media API, and this can be quite tricky, but here's [a post](https://community.atlassian.com/t5/Jira-questions/Re-Linking-inline-image-to-attachment-using-API/qaq-p/2183997/comment-id/555940#M555940) on this if you're interested.

Alternatively, an easier way would be to insert the attachment as an external URL instead (outlined [here](https://community.atlassian.com/t5/Jira-questions/Re-How-can-I-add-an-image-in-a-comment/qaq-p/1918756/comment-id/515362#M515362)), where we can use the "regular" Jira attachment ID. I've tested this and seems to work fine!  

```
{
    "body": {
        "type": "doc",
        "version": 1,
        "content": [
            {
                "type": "mediaSingle",
                "content": [
                    {
                        "type": "media",
                        "attrs": {
                            "type": "external",
                            "url": "https://<instance-name>.atlassian.net/rest/api/3/attachment/content/10000"
                        }
                    }
                ]
            }
        ]
    }
}
```

comments: author: Laxman Khokhar
body: { "body": { "type": "doc", "version": 1, "content": \[ { "type": "paragraph", "content": \[ { "type": "text", "text": "Test comment" } \] }, { "type": "mediaSingle", "content": \[ { "type": "media", "attrs": { "id": "113844", "type": "external" } } \] } \] } }

i m passing above json payload to save comment and give a error {"errorMessages":\["INVALID_INPUT"\],"errors":{}} how to resolve this issue and anything else from my end in header in passing?


author: Sadiq Satriya
body: Hi [@Laxman Khokhar](/t5/user/viewprofilepage/user-id/5556096) ,

From the latest payload you provided, it looks like you're still passing in the "id" directly, but it should be a "url" attribute. The *attrs* object should be as follows:  

```
"attrs": {
  "type": "external",
  "url": "https://<instance-name>.atlassian.net/rest/api/3/attachment/content/<Jira-Attachment-ID>"
}
```

As for the headers, [the docs](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-comments/#api-rest-api-3-issue-issueidorkey-comment-post) example includes these two:

```
Accept: application/json
Content-Type: application/json
```


author: Laxman Khokhar
body: {  
"body": {  
"type": "doc",  
"version": 1,  
"content": \[  
{  
"type": "paragraph",  
"content": \[  
{  
"type": "text",  
"text": "Here is an attachment:"  
},  
{  
"type": "media",  
"attrs": {  
"type": "external",  
"url": "<https://mydomain/rest/api/3/attachment/content/113878>"  
}  
}  
\]  
}  
\]  
}  
}  
i am passing above payload but give me error and try many way but not did any solution.  
Error :  
{  
"errorMessages": \[  
"INVALID_INPUT"  
\],  
"errors": {}  
}


author: Laxman Khokhar
body: Hi [@Sadiq Satriya](/t5/user/viewprofilepage/user-id/368512)

Your given payload is working fine for me.

Thank you.


Tags: cloud

jira-cloud

jira-service-management

jira-service-management-cloud