Bulk create issue with updates. Code 400 after adding worklog

Hello,
Is there a way to add worklog to newly created issue by using “POST /rest/api/2/issue/bulk” endpoint? Documentation says that it could be done by adding “update” node to json body. So I am adding update node as below:

"update": { "worklog": [ { "add": { "timeSpent": "2d" } } ] },

I have successfully created an issue without worklog, but still getting code 400 in server response when it is added.

{"issues":[],"errors":[{"status":400,"elementErrors":{"errorMessages":[],"errors":{"worklog":"Field 'worklog' cannot be set. It is not on the appropriate screen, or unknown."}},"failedElementNumber":0}]}

I knew that fields should be set as configured on “create issue screen” when I am using “POST /rest/api/2/issue” endpoint, but I thought that bulk issue creation could be a solution for creating an issue and updating it’s fields at once. After a few hours of work I can’t see any option to do issue transition and to add worklog with API bulk request. Could anyone provide me some information if it is possible or not? If it is possible, how should I use “update” node?

Thank you in advance,

Hello @Robert

If you are on Jira Cloud, you really should wean yourself off the old v2 endpoints and move to using the v3 endpoints, because development and support of the v2 REST API ended many years ago.

Try using the v3 Update worklog endpoint first to see if you can update a single worklog for a single issue before you try using the v3 Create issue or Bulk create issue endpoints.

2 Likes

@sunnyape Thank you for fast response. Unfortunately, on v3 API the problem also occurs. My generated json body below:

{ "issueUpdates": [ { "transition": { "id": "11", "looped": false }, "update": { "worklog": [ { "add": { "timeSpent": "2d" } } ] }, "fields": { "summary": "Some problem", "issuetype": { "id": "10007" }, "duedate": "2021-12-16T00:00:00", "description": { "version": 1, "type": "doc", "content": [ { "type": "paragraph", "content": [ { "type": "emoji", "attrs": { "shortName": ":slight_smile:", "id": "1f642", "text": "🙂" } }, { "type": "text", "text": " emoji " } ] } ] }, "project": { "key": "XBG" }, "reporter": { "id": "<real Id here>" }, "assignee": { "id": "<real Id here>" }, "priority": { "id": "1" }, "labels": [ "server" ], "timetracking": { "originalEstimate": null, "originalEstimateSeconds": null, "remainingEstimate": "1w", "remainingEstimateSeconds": null, "timeSpent": null, "timeSpentSeconds": null } } } ] }

With empty “update” node I can create an issue without problems in both API versions.

@Robert

You haven’t advised if you did or did not test updating just the worklog of an existing issue via the Update worklog endpoint first, and if it did or did not work. This would be the basic test to confirm that the ‘Log Work’ field is actually on the Create and Edit screens for that issue type.

The other confirmation would be to log into Jira via the web UI using the same credentials as your REST API connection, create a new issue of the same issue type, and check that you can see that the ‘Log Work’ field is available and you can to set its values:

If that field is not on those screens, then of course you will get the classic “Field ‘blah-blah’ cannot be set. It is not on the appropriate screen, or unknown.” error.

@sunnyape As you said, I’ve logged into Jira using same credentials as I use for REST API. I can confirm that on create issue screen, there are no “Log work” checkbox and “Time spent” fields.

But on edit issue screen there is “Time spent” field, I can fill it and update issue with. I can also say, that I only use fields that exists in this project.

Is it possible to use “update” node to update an issue without adding field to create issue screen, if that field exists in edit issue screen? Of course I know that I can edit issue after creation using different API method. I wanted to use bulk create, to send fewer requests.

Thank you for fast response,

hello @Robert

Why you just don’t add the Log Work field to the issue’s create screen, which is the root cause of that part of your REST API call failing? Why create an elaborate work-around by updating a field after you create the issue?

Anyhow, now that I’ve found the cause of the initial problem for you, I’ll leave it up to you to decide which method of resolving the remaining problem works best for you.

@sunnyape Thanks for suggestion, but I already have workaround by simply using Create and Edit REST API methods one after another.

Doing workaround is not a resolution for me. I wanted to use bulk create method to do fewer API requests. It seems, that I am doing something wrong or this method is completely unusable. Only create part of this method works as described in documentation. Transitions are not working for me and updates also. I would appreciate if anybody confirm (or not), that this method works as I think.

Thank you in advance.

@Robert

I’ve given you the answer, three times. If the field ‘Log Work’ isn’t on the Create screen of that issue type THEN YOU CANNOT UPDATE ITS VALUE WHEN CREATING THE ISSUE VIA THE REST API. It’s really that simple.

Since you have confirmed that field isn’t available on the Create screen of that issue type, only the ‘Time tracking’ field, which is a totally different field with a totally different purpose, then that is the root cause of the problem.

As for whether or not the Bulk issue create REST API endpoint works, it does. Here is where I just tested it using Postman: