What is wrong with this Google Script RestAPI request?

Wade Lyman July 20, 2021
function makePostRequest() {
var data = { "fields": { "project":{ "key": "****" }, "priority": { "name": "Medium" }, "duedate": "test", "summary": "summary", "description": "description", "issuetype":{ "name": "Task" } }};
const url = "https://*****.atlassian.net/rest/api/latest/issue"; const response = UrlFetchApp.fetch(url, { "method": "POST", "headers": { "X-Atlassian-Token" : "no-check", "Authorization": "Bearer ************", "Accept": "application/json", "Content-Type": "application/json" }, "muteHttpExceptions": true, "followRedirects": true, "validateHttpsCertificates": true, "contentType": "application/json", "payload": JSON.stringify( { "fields": { "project":{ "key": "INFOSEC" }, "Priority": { "name": "Medium" }, "Description": "description", "issuetype":{ "name": "Task" } } } ) });
Logger.log("Response code is %s", response.getResponseCode()); Logger.log(response.getContentText());}
 Error: {"errorMessages":[],"errors":{"Priority":"Field 'Priority' cannot be set. It is not on the appropriate screen, or unknown.","Description":"Field 'Description' cannot be set. It is not on the appropriate screen, or unknown."}}

I have checked the screens and they are correctly configured and I have admin and developer access to all of them, so I assume it's an issue with my request.

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 21, 2021

Yes I think the "var data = ... " is in the correct format ... but you are posting a different payload where Priority and Description field id are capitalized.

Try with "payload": JSON.stringIfy( data )

Suggest an answer

Log in or Sign up to answer