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.
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());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.