It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Editing an issue via Google script and JSON

Rea Krakover Nov 07, 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?

3 answers

1 accepted

0 votes
Answer accepted
Gregor Kasmann Nov 07, 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 Nov 08, 2017

Thanks, answer accepted

0 votes
Alexey Matveev [cPrime] Community Leader Nov 07, 2017 • edited

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

0 votes
Rea Krakover Nov 08, 2017

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

1,265 views 2 13
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you