Editing an issue via Google script and JSON

i'm trying to edit an existing through Google script.

I've researched and came up with this code:

function sendData() {
var username = "username";
var password = "password";
var encCred = Utilities.base64Encode(username+":"+password);

var url = "https://<base URL>/rest/api/2/issue/";
var data = { "fields": {"summary": "new summary edit"} };
var payload = JSON.stringify(data);

var headers = {
"Accept":"application/json",
"Content-Type":"application/json",
"Authorization":"Basic " + encCred,
};

var options = {
"method":"POST",
"contentType" : "application/json",
"headers": headers,
"payload" : payload
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response);
}

But i'm getting an error

Request failed for.... returned code 405

What am i missing here? any idea why this won't work?

3 answers

1 accepted

Accepted Answer
0 votes

To editing an issue you shoud use this REST: https://docs.atlassian.com/jira/REST/7.4.0/#api/2/issue-editIssue

Pay attention to:

 var url = "https://<base URL>/rest/api/2/issue/{issueIdOrKey}";
"method":"PUT",

Thanks, answer accepted

0 votes

Hello,

You use POST /rest/api/2/issue/. This REST function creates an issue, but you do not provide project and issue type. Your playload is wrong

Thank you guys for your help!

using @Gregor Kasmann reference, i've changed the data variable to 

{"update":{"summary":[{"set":"Bug in business logic"}]}}; 

the url to 

var url = "https://<base URL>/rest/api/2/issue/41335";

and changed the method in the options var to

"method":"PUT",

 

And now it works! 

Thank you very much!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

25,694 views 2 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you