How do I set an Assignee on Issue Creation in the API?

Joe Osborne August 4, 2021

I want to be able to set the assignee for issues when I create them via the API.  

However, whatever info I send results in the same error:  Field 'assignee' cannot be set. It is not on the appropriate screen, or unknown

 

I do know there's an API endpoint for assigning to known tickets, however, I need to perform this action on issue creation, and that's not working.

3 answers

0 votes
david_renton
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 29, 2022

OK, for all the Python people that arrive here after, here is how I've accomplished getting user id's emails and names so I can assign tickets to them.

def get_assignable_users(start_from):
auth, headers, base_url = auth_and_headers()
url = f"{base_url}/rest/api/3/user/assignable/search"

query = {
'project': 'ONE OF YOUR PROJECT KEYS',
'startAt': start_from
}

response = requests.request(
"GET",
url,
headers=headers,
params=query,
auth=auth
)
return response


if __name__ == "__main__":
start = 0
my_json = {}
while start is not None:
user_list_response = get_assignable_users(start)
text = json.loads(user_list_response.text)
for user in text:
my_json[f"{user['emailAddress']}"] = user['accountId']
if len(text) == 100:
start = start + 100
else:
start = None

with io.open('json_users.json', 'w') as outfile:
json.dump(my_json, outfile)

The outputted json_users file can be imported into your script and queried by email address to get the id.

0 votes
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2021

Hi @Joe Osborne

Did you take a look at these examples? https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/

If assignee is a mandatory field, then you have to include it in your API.

Let me know if the above helps.

Alex

Joe Osborne August 4, 2021

Thanks, I'm familiar with the examples and am including the assignee in my request.

Like Dane Kantner likes this
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2021

Then see if the assignee field is present on that issue type create screen. If not, add it on the screen.

Joe Osborne August 4, 2021

I'm not sure what you mean by "screen".  

 

I'm working through python with the API so I don't see any screens.

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2021

Yes, you might work with python, but "screens" is a Jira essential feature.

When you create an issue/ticket on Jira, a popup screen appears, which prompt you to complete certain fields (mandatory and optional). Screens can also be used on workflow transitions. Screens are also used when a user creates, view or edit an issue. So even if you don't see any screen, they do exist.

With that said, you have to check if the assignee field is present on the creation screen. If not, then you have to add it. If you are not a jira admin, then you have to inform a jira admin to add this field to the creation screen of the project of the issue type you are trying to create.

Sorry to tell you that, but screens, field, schemes etc are Jira basic terminology and you should start to get accustom with them (even if you use REST API).

Joe Osborne August 4, 2021

The assignee field is present on the Create Issue screen with the user I'm working with the API with.

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2021

Please post here your API command, as well as the issue create screen.

Joe Osborne August 4, 2021

createIssue = {
"fields": {
"assignee": {
"name": "username"
},
}
}
issue = session.post('https://site.name/rest/api/2/issue', json=createIssue)

 

Capture.PNG

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2021

So "username" is the actual name of the user?

Joe Osborne August 4, 2021

Yes, I changed this value to something safe for public posting, but that value is the user's actual name.

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2021

Ok then. Can you take a look at this post https://community.atlassian.com/t5/Jira-questions/Jira-REST-API-getting-error-unable-to-create-an-issue-using/qaq-p/1399628

It seems that another was facing the same issue with you. It could be that the main problem could be that are using fields' names instead of identifiers. Give it a try and let me know if that worked.

Joe Osborne August 5, 2021

Thanks, but I noted this post already.  Their problem was malformed requests, which I think is ok as it's working in the assignee endpoint.  

Strangely it doesn't work with new issue creation though.  

Like Dane Kantner likes this
Dane Kantner August 9, 2021

I'm seeing similar; works fine w/ an update after but not in a new issue create

Scott Chapman June 16, 2022

For those who come here later: I was able to get this to work with 

 "assignee": {"id":"62abc....501ee"}

I found the required ID by exporting to XML an issue with the correct user assigned. 

Also suggested elsewhere that accountid instead of id might work. 

Like # people like this
0 votes
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2021

Are you able to set the Assignee during issue creation in the UI, under the same identity you are using for the API?

Joe Osborne August 4, 2021

I can successfully assign an assignee using the assignee endpoint:

PUT /rest/api/2/issue/{issueIdOrKey}/assignee

 

However, when I include the same request on a ticket creation request, I get the error mentioned above:  Field 'assignee' cannot be set. It is not on the appropriate screen, or unknown

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2021

I am asking if you can set the Assignee field during issue creation when you use the web UI and the same identity you use for the API.

Is the destination project for the new issue a Team Managed project or a Company Managed project?

Try logging into the Jira web application with the identity you use for your API call. Try using the UI to create an issue in the desired project. Is the Assignee field available there?

If the Assignee field is not available in the Create Issue UI screen for your project and the issue type you are trying to create, then you will not be able to set the value using the Create Issue API.  

Joe Osborne August 4, 2021

The assignee field is present on the Create Issue screen with the user I'm working with the API with.

Like Dane Kantner likes this

Suggest an answer

Log in or Sign up to answer