Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

What is wrong with this Google Script RestAPI request?

Wade Lyman
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
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
PD Sheehan
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.
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