How Can We Add Comment Using Edit Endpoint

I have a Java project in which I’m trying to interact with our Jira Cloud Platform. The current task that I’m working on is to insert a comment on a ticket using /edit endpoint. I know there is an endpoint just for inserting comments, but I want to use /edit endpoint.

Based on Atlassian Example it should be pretty straight-forward. We should send a PUT request with the following body:

{
   "update": {
      "comment": [
         {
            "add": {
               "body": "It is time to finish this task"
            }
         }
      ]
   }
}

I create the exact same body in my Java code like this:

private String createEditBody() {
    JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
    ObjectNode payload = jsonNodeFactory.objectNode();
    ObjectNode update = payload.putObject("update");
    ArrayNode comments = update.putArray("comment");
    ObjectNode add = comments.addObject();
    ObjectNode commentBody = add.putObject("add");
    commentBody.put("body", "this is a test");
    return payload.toString();
}

but when I send this PUT request I get an error saying that the “Operation value must be of type Atlassian Document Format”!

I’m trying to figure out the ADF format and since it seems like it needs “version”, “type” and “content” I changed my code to make the body like this:

{
  "update": {
    "comment": [
      {
        "add": {
          "version": 1,
          "type": "paragraph",
          "content": [
            {
              "body": "this is a test"
            }
          ]
        }
      }
    ]
  }
}

but now I get 500 (internal server error). I’m assuming that this should be a pretty simple thing to do, I was surprised not being able to find anything online and Atlassian example seems to be inaccurate! Appreciate any help here.

Total stab in the dark, but try and send your ADF in the body field instead. Let me know if that doesn’t work.

1 Like

Thanks a lot for your response, it actually helped! I created this body:

{
  "update": {
    "comment": [
      {
        "add": {
          "body": {
            "version": 1,
            "type": "paragraph",
            "content": [
              {
                "type": "text",
                "text": "this is a test",
              }
            ]
          }
        }
      }
    ]
  }
}

The issue is that now it returns 204 but I don’t see the comment on ticket!! do you have any ideas what’s wrong?

After tinkering with the body, I made this change and fixed the issue:

{
  "update": {
    "comment": [
      {
        "add": {
          "body": {
            "version": 1,
            "type": "doc",
            "content": [
              {
                "type": "paragraph",
                "content": [
                  {
                    "type": "text",
                    "text": "this is a test"
                  }
                ]
              }
            ]
          }
        }
      }
    ]
  }
}

The annoying part is:

  • Jira’s documentation is WRONG
  • After sending the wrong input (the one in comment) I was getting 204!!!

But on the bright side, it is fixed now!

What part of the documentation was wrong? Happy to bump that over to the appropriate team :slight_smile:

1 Like

Thanks for your follow-up, in this link there is a section called Adding a comment using the edit issue method which suggests sending this input data:

{
   "update": {
      "comment": [
         {
            "add": {
               "body": "It is time to finish this task"
            }
         }
      ]
   }
}

(already mentioned all of this in my question)

Ah, I see the issue—that documentation is for Jira server, which doesn’t support ADF. You’re on Jira Cloud, which requires it.

I think it would be very beneficial and way less confusing to have these examples for both Jira service and Jira cloud, specially for the latter since the ADF is less intuitive at least for those who haven’t worked with it.
Adding a comment with edit endpoint should be very trivial thing to do but because I couldn’t find any proper explanation online, it took me a few days whereas for changing assignee of a ticket that I did in less than 5 minutes! The only difference between these two was that I could figure how to do the latter using Jira’s documentation but not the former!

Hello

I can add a comment using the edit endpoint, I need to use this endpoint, and not the comment one, but I can not make it internal, I have tried:

 "jsdPublic": false

also

"properties": [
    {
      "key": "sd.public.comment",
      "value": {
        "internal": true
      }
    }
  ]

Only thing that can change visibility is this, but this does not make it internal

 "visibility": {
    "identifier": "Administrators",
    "type": "role",
    "value": "Administrators"
  }

can you help me?