Editing an issue via Google script and JSON

Rea Krakover November 7, 2017

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?

4 answers

1 accepted

1 vote
Answer accepted
Gregor Kasmann_Actonic
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2017

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",
Rea Krakover November 8, 2017

Thanks, answer accepted

2 votes
Rea Krakover November 8, 2017

Thank you guys for your help!

using @Gregor Kasmann_Actonic 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!

0 votes
ku ku Shiva April 3, 2020

Is fetch working successfully, Im getting BAD Request error. Im trying to integration Google sheet online. 

If possible pls share the code.

UrlFetchApp.fetch(url, options);
  
0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2017

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

Suggest an answer

Log in or Sign up to answer