'Create/Update Subtask for a Jira Story
I am new to Jira API & I am currently creating a google form to create a subtask automatically for any ad-hoc requests attaching to an existing story that is already created manually.
URL: https://<subdomain>.atlassian.net/jira/software/c/projects/<PROJECTID> STORY CREATED: PROJECTID-XXX
I have the following sample code to test:
function createSubTask(summary, description) {
var URL = 'https://<subdomain>.atlassian.net/rest/api/3/issue';
var username = '<user-name>';
var password = '<api-key>';
var userCreds = "Basic " + Utilities.base64Encode(username + ':' + password);
var data = {
"project": {"key": "PROJECTID"},
"parent": {"key": "PROJECTID-XXX"},
"summary": summary,
"description": description,
"issuetype": {"name":"Sub-task"}
};
var payload = JSON.stringify(data);
var headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": userCreds,
"muteHttpExceptions": "True"
};
var options = {
"method": "POST",
"headers": headers,
"payload": payload
}
var response = UrlFetchApp.fetch(URL, options);
Logger.log(response);
}
I am getting the following error:
Exception: Request failed for https://<subdomain>.atlassian.net returned code 400. Truncated server response: {"errorMessages":[],"errors":{"project":"Specify a valid project ID or key"}} (use muteHttpExceptions option to examine full response)
Not sure, what I am doing wrong.
Solution 1:[1]
Use the following payload format. It will fix the problem.
{
"fields": {
"project":
{
"key": "TEST"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Compositr |
