Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

REST API v3 Posting comment returns 404

Curtis McIntyre April 4, 2023

I'm able to create new issues via API, but I'm receiving 404 returns on the following:


var jiraComment = message.getSubject();
var issueKey = matchedValue;
var url = "https://COMPANY.atlassian.net/rest/api/latest/issue/"+issueKey+"/comment";
var data = {
"body": {
"content": [
{
"content": [
{
"text": jiraComment,
"type": "text"
}
],
"type": "paragraph"
}
],
"type": "doc",
"version": 1
},
// "visibility": {
// "identifier": "Administrators",
// "type": "role",
// "value": "Administrators"
// }
};
var payload = JSON.stringify(data);
var headers = 
      { 
        "content-type": "application/json",
        "Accept": "application/json",
        "authorization": "Basic APIKEY"};

var options = 
      { 
        "content-type": "application/json",
        "method": "POST",
        "headers": headers,
        "payload": payload
      };
var response = UrlFetchApp.fetch(url, options);
 Logger.log(response.getContentText());
var dataAll = JSON.parse(response.getContentText());
var commentId = dataAll.id
  Logger.log(commentId);

 

When I take the manually created url in my browser I'm able to return appropriate results.

I use the same APIKEY to create the jira, so I figured it should work here as well.

2 answers

1 accepted

0 votes
Answer accepted
Curtis McIntyre April 6, 2023

I was premature in accepting my own answer, the problem actually was in the generation of the authentication.  For some reason the formatting used within the creation of the jiras is not acceptable in my environment for comments.

Was able to successfully use postman with same APIKEY and used the headers from that into the app script to allow the posting of comments.

0 votes
Curtis McIntyre April 4, 2023

Here's the correct snippet for future issues;

var jiraComment = message.getSubject();
var issueKey = matchedValue;
var url = "https://COMPANY.atlassian.net/rest/api/latest/issue/"+issueKey+"/comment";
var data = {
"body": jiraComment,
};
var payload = JSON.stringify(data);
var headers =
{
"content-type": "application/json",
"Accept": "application/json",
"authorization": "Basic APIKEY"
};
var options =
{
"content-type": "application/json",
"method": "POST",
"headers": headers,
"payload": payload

};
var response = UrlFetchApp.fetch(url, options);
//  Logger.log(response.getContentText());

Suggest an answer

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

Atlassian Community Events