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

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 vote

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 (Actonic GmbH) 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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira

Mission-critical battery manufacturer fulfills FAA software requirements with Commit Policy Plugin

EaglePicher Technologies is a leading manufacturer of battery systems for diverse industries like defense, aviation, space or medical. As they operate in highly regulated industries, keeping a clear ...

165 views 0 2
Read article

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