Posting external link as comment to Jira using Node.js

greg chap
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 3, 2019

I am posting a comment with some text and external link combined as string using jira rest api(v3). Looks like below


"text [test|https://www.test.com]"

Comment shows up as normal text without external link on the jira issue. Because it adds a **backslash** before the first square bracket. Even though it looks correct on jira ticket, as soon as I select Edit on the comment, i see


text \[test|https://www.test.com]

so I tried unicode for the square bracket and posted comment like below


text [test|https://test.com]

It shows correctly as comment, but again without the external link. I tried adding couple of \\ before the first square bracket, I tried double square brackets around the external link as well, but no luck.


I am following the documentation they had for adding comment right below

 https://developer.atlassian.com/cloud/jira/platform/rest/v3/?utm_source=%2Fcloud%2Fjira%2Fplatform%2Frest%2F&utm_medium=302#api-rest-api-3-issue-issueIdOrKey-comment-post 

Basically my request is as below


var bodyData = `{
"visibility": {
"type": "role",
"value": "Administrators"
},
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "text [test|https://www.test.com]",
"type": "text"
}
]
}
]
}
}`;

var options = {
method: 'POST',
url: '/rest/api/3/issue/{issueIdOrKey}/comment',
auth: { username: 'email@example.com', password: '<api_token>' },
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: bodyData
};

request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(
'Response: ' + response.statusCode + ' ' + response.statusMessage
);
console.log(body);
});

Any thoughts on what I am missing?

0 answers

Suggest an answer

Log in or Sign up to answer