Forums

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

REST API — Error when trying to create an issue from Google App Script

Martin Bonneville October 22, 2020

Hi,

I'm using a Google Sheet to get all stories from the current sprint and calculate some stats.

Now, I'm trying to create a new issue in jira from the same Google Sheet.

function postNewBugToAPI() {
var host = SpreadsheetApp.getActiveSpreadsheet().getRange("Host").getValue();
var url = "https://" + host + "/rest/api/3/issue";
var digestfull = PropertiesService.getUserProperties().getProperty("digest");


var issueData = {"fields":
{"project": { "key": "OMC" }, // Set the Project
"issuetype": {"name": "Bug"}, // Set the Bug
"summary": "This is a test" // Set the Summary
}
};

// Call the Jira API
var payload = JSON.stringify(issueData);

var headers = { "Accept":"application/json",
"Content-Type":"application/json",
"method": "POST",
"headers": {"Authorization": digestfull},
"muteHttpExceptions": true
};

var options = {"method":"POST",
"Content-Type":"application/json",
"headers": headers,
"payload" : payload
};

var resp = UrlFetchApp.fetch(url, options );

if (resp.getResponseCode() != 200) {
Browser.msgBox("Error retrieving data for url " + url + ":" + resp.getContentText());
return "";
}
else {
return resp.getContentText();
}

}

I always get this error:

Request failed for https://XYZ.atlassian.net returned code 400. Truncated server response: {"errorMessages":[],"errors":{"summary":"Field 'summary' cannot be set. It is not on the appropriate screen, or unknown."}} (use muteHttpExceptions option to examine full response) (line 189, file "Code")

I've used this call to ensure that the field is available:

https://XYZ.atlassian.net/rest/api/3/issue/createmeta?expand=projects.issuetypes.fields&projectKeys=OMC&issuetypeIds=1

Here's the related answer section:

"summary": {"required": true,"schema": {"type": "string","system": "summary"},"name": "Summary","key": "summary","hasDefaultValue": false,"operations": ["set"]},

 

Someone have an idea what I'm missing?

 

Thanks,

Martin

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events