Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

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

When saving a comment with an attachment,please provide the proper payload and how to resolve issue?

Laxman Khokhar August 7, 2024

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

1 answer

1 accepted

0 votes
Answer accepted
Sadiq Satriya August 9, 2024

Hi @Laxman Khokhar ,

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 on this if you're interested.

Alternatively, an easier way would be to insert the attachment as an external URL instead (outlined here), 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"
                        }
                    }
                ]
            }
        ]
    }
}
Laxman Khokhar August 9, 2024

{ "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?

Sadiq Satriya August 9, 2024

Hi @Laxman Khokhar ,

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 example includes these two:

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

 

Laxman Khokhar August 9, 2024
{
  "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": {}
}
Laxman Khokhar August 9, 2024

Hi @Sadiq Satriya 

Your given payload is working fine for me.

Thank you.

Suggest an answer

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

Upcoming Jira Service Management Events