ashkanent
ashkanent

Reputation: 235

Jira API: Add Comment Using Edit Endpoint

Jira has a an /edit endpoint which can be used to add a comment. There is an example in their documentation that suggests this input body to accomplish this:

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

I create the exact same input in my Java code:

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"!

Checking the ADF format it says that "version", "type" and "content" are required for this format. So although their documentation example doesn't seem to be ADF format, I'm trying to guess the format and change it. Here's what I accomplished after modifying my code:

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

the add operation seems to be an ADF but now I get 500 (internal server error). Can you help me find the issue?

Note that the above example from Atlassian documentation is for "Jira Server Platform" but the instance I'm working with is "Jira Cloud Platform" although I think the behaviour should be the same for this endpoint.

Upvotes: 3

Views: 1405

Answers (1)

ashkanent
ashkanent

Reputation: 235

after tinkering with the input body, I was able to form the right request body! This will work:

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

The annoying things that I learned along the way:

  • Jira's documentation is WRONG!! Sending the request in their example will fail!!
  • after making a few changes, I was able to get 204 from the endpoint while still comment was not being posted! And I guessed that the format is not correct and kept digging! But don't know why Jira returns 204 when it fails!!!

Upvotes: 2

Related Questions