Hi,
Following the Jira API instructions on creating an issue here:
https://developer.atlassian.com/server/jira/platform/rest-apis/
https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/
I have a JSON file with multiple records; how do I get ALL of the records created as Jira issues when I do a POST to the https://[hostname]/rest/api/2/issue/ endpoint?
If I leave out the array tags "[" and "]" at the beginning and end of the file respectively, then when I do a post, only the first record is created. If I include those array tags, then I get an error:
Can not deserialize instance of com.atlassian.jira.rest.v2.issue.IssueUpdateBean out of START_ARRAY
Thanks,
Tim
Hello,
You should use the POST /rest/api/2/issue/bulk endpoint:
Thank you, I didn't know about that endpoint. But now I'm getting this error:
{"errorMessages":["No issue data was provided by request"],"errors":{}}
I confirmed that I have valid json in my file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How did you confirm that you have a valid Json? Jira says there is no issue data.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just dumped the data into an online validator tool (I used https://jsonlint.com/). In any case, I was able to do this a different way by using the original issue endpoint and then just iterating over each JSON object and creating issues one by one.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you validated a json, it does not mean that it will work. It must be of the required structure and your json is not.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, well,l as I noted, I rewrote my code so that it just feeds one JSON object at a time to the issue endpoint and that worked, so still not sure why the bulk endpoint did not. At this point, I can close this topic.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you're using Python and Requests library following might be helpful.
In your post request don't forget to give data attribute the issues in json format
url='https://www.random.com'
data=json.dumps(all_issues)
headers={'Content-Type': 'application/json'}
response = requests.post(url, data=data, headers=headers)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm getting the same:
No issue data was provided by request
And I'm like 90% sure the req body is formatted right, according to those docs. Is this just an outdated endpoint?
I could do what Tim did and just iterate through them, but that's not a great solution if you have a lot of issues to create.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nevermind. I got it working!
All the fields besides update are subdfields of "fields". Here is my working code:
const issuesToCreate: {
update: object;
fields: { project: { id: number },
summary: string,
issuetype: { id: number },
description: string,
assignee?: { name: string } | null,
}}[] = [];
actionItems.forEach((actionItem: ActionItem) => {
issuesToCreate.push({
update: {},
fields: { project: { id: project.id} ,
summary: actionItem.title,
description: actionItem.actionItem,
issuetype: { id: selectedIssueType.id },
...(actionItem.responsibleParty ? {
assignee: {
name: actionItem.responsibleParty
}
} : {})
}})
});
// Post to the bulk create API route to create the actual issues on Jira
const issueCreateResponse = await fetch(`https://${integration.Domain}/rest/api/2/issue/bulk`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": authHeader
},
body: JSON.stringify({issueUpdates: issuesToCreate}),
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.