Unable to add custom properties to comments in jira

Hi there,

I am unable to add custom properties to the comments while creating the comment using the following JIRA rest api endpoint,
POST /rest/api/2/issue/{issueKey}/comment

I am sending the following data to the endpoint,

{
	"body": {
    "type": "doc",
    "version": 1,
    "content": [
      {
        "type": "paragraph",
        "content": [
          {
            "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
            "type": "text"
          }
        ]
      }
    ]
  },
  "properties":[
  	{"key":"key1",
  	"value":"Value1"}]
}

If I remove the “properties” key from the request data the comment creation succeeds else it throws the following error with status code 500,

{
“errorMessages”: [
“Internal server error”
],
“errors”: {}
}

Am I doing something wrong? How do I add custom properties while creating comment in Jira?

Hi @Gaurav,

Sorry to see you waited so long for a reply, I’ve done a bit of testing and I believe this is the format you would need to set a key:

{
	"body": {
    "type": "doc",
    "version": 1,
    "content": [
      {
        "type": "paragraph",
        "content": [
          {
            "text": "issue Property.",
            "type": "text"
          }
        ]
      }
    ]
  },
  "properties":[
  	{
    	"key": "key1",
    	"value": 
      	{
        	"value1": "Value",
            "value2": "Value"
    	}
    }
  ]
}

Retrieving the value using the endpoint GET /rest/api/3/comment/{commentID}/properties/key1, would return

{
    "key": "key1",
    "value": {
        "value1": "Value",
        "value2": "Value"
    }
}

I hope that helps.
Cheers,
Melissa

1 Like

@mpaisley Hello i am trying the same in Jira cloud script Listener Script listener
With this code

def payload = [
body: comment.body,
properties: [“value”:“key”],
author: null
]
//logger.info(“payload: ${payload}”)

def commentResp = post("/rest/api/2/issue/${wardId}/comment")
    .header('Content-Type', 'application/json')
    .body(payload)
    .asObject(Map)


logger.info("Response: ${commentResp}")
assert commentResp.status == 201

but I i get a error invalid request payload:

2024-04-09 13:47:50.801 INFO - Serializing object into ‘interface java.util.Map’
2024-04-09 13:47:50.801 INFO - POST /rest/api/2/issue/431734/comment asObject Request Duration: 213ms
2024-04-09 13:47:50.802 WARN - POST request to /rest/api/2/issue/431734/comment returned an error code: status: 400 - Bad Request
body: {errorMessages=[Invalid request payload. Refer to the REST API documentation and try again.]}
2024-04-09 13:47:50.802 INFO - Response: status: 400 - Bad Request
body: {errorMessages=[Invalid request payload. Refer to the REST API documentation and try again.]}
2024-04-09 13:47:50.811 ERROR - Assertion failed:

assert commentResp.status == 201
| | |
| 400 false
status: 400 - Bad Request
body: {errorMessages=[Invalid request payload. Refer to the REST API documentation and try again.]}

2024-04-09 13:47:50.816 ERROR - Class: com.adaptavist.sr.cloud.events.WebhookExecution, Config: null

@HugoUnknown rather than replying to a post from 4 years ago, I’d recommend creating a new post (you can always write something like “I saw this similar post and tried the suggestion”) as there’s no guarantee the same person who originally answered will be available to reply, and it’s possible that things may have changed in that time.

1 Like

@HugoUnknown if you’re still stuck, the answer is actually the same as it was for Gaurav - here’s another example - hopefully it’s a little clearer:

var bodyData = `{
    "body":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
    "properties":[
      {
        "key": "myKey",
        "value": {"dataKey": "Data"}
      }
    ],
    "author":null
  }`;

So, for the properties, you need to have defined an array of {"key": [String], "value": [JSON Object]} - in your example you have defined an array with {"value": [String]} which isn’t valid

Hope that clarifies!
Mel

1 Like