const createSubtasks = async () => {
const parentIssueKey = context.extension.issue.key; // Use issue key instead of ID
const projectId = context.extension.project.id; // Continue using project ID
const projectKey = context.extension.project.key;
const issueType = await getID(projectId); // Get the subtask issue type ID
if (!issueType) {
console.error("No valid subtask issue type found.");
return;
}
const requestBody = {
"fields": {
"project": {
"key": projectKey
},
"parent": {
"key": parentIssueKey
},
"summary": "Subtask Example",
"description": {
"type": "doc",
"version": 1,
"content": [{
"type": "paragraph",
"content": [{
"text": "This is a detailed description of the subtask.",
"type": "text"
}]
}]
},
"issuetype": {
"id": issueType
}
}
};
const response = await requestJira("/rest/api/3/issue", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(requestBody)
});
if (response.status === 201) {
console.log("Subtask created successfully!");
} else {
console.error("Failed to create subtask:", await response.text());
}
};
And I'm getting this error message: Failed to create subtask: {"errorMessages":[],"errors":{"parentId":"Given parent issue does not belong to appropriate hierarchy."}}
And I don't know what else to do because I'm getting the actual key and id of the issue that I want to work on. And I can add subtasks to this issue with no problem by using the Jira software.
Can someone help me?
Thanks!