Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,555,438
Community Members
 
Community Events
184
Community Groups

REST API v3 Posting comment returns 404

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

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.

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