JIRA REST API cant get account id to create issue with requestor

Yakov Borukhov July 26, 2021

Hi

Im building a program that creates jiras for others. I want to make them the requestor of the jira. I understand i need to get their account ID, but i havent found a way to get it. All the proposed solutions didnt give me the account id. For example:

This url returns a null for uri status code of 404. If i change the 2 to 3, i get dead link. 
https://jira.companyName.net/rest/api/2/user/bulk/migration?username=123456

This url returns data, but it doesnt contain accountid.
https://jira.companyName.net/rest/api/2/user?username=123456

I can't even find my own account id, even though i specifically created an atlassian account. 

 Am i only limited to using an accountid to perform this action or are there other ways? Please let me know what i should do.

Thank you 

 

1 answer

1 accepted

0 votes
Answer accepted
David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 26, 2021

Hello @Yakov Borukhov 

Your question contains the tags 'jira-server' and 'server', so I assume you have Jira Server, not Jira Cloud.

The bulk get users REST API endpoint is a v3 endpoint, so it only works with Jira Cloud; you can't make v3 endpoints work for Jira Server just by changing the '3' to a '2'. All the v2 REST API endpoints for Jira Server are documented here (this is for server v8.14.0)

Next, you are looking for something that doesn't exist. Account IDs are a feature of Jira Cloud, not Jira Server, so that's why there is no account ID in the response to the GET request to the /rest/api/2/user endpoint.

I get the feeling you've led yourself astray by reading the wrong product documentation. If you are using Jira Server, read only the REST API documentation for it, not for for Jira Cloud.

Yakov Borukhov July 27, 2021

I appreciate the response. Thanks for clearing up the difference between JIRA cloud and JIRA server and for providing the link for the documentation. The reason i started looking for account ids was because i kept getting a 'Bad Request' response when i set a name for the reporter. No matter what username i put, i cant create a jira. If i exclude reporter from the JSON, i am able to successfully create a jira. Im not sure what the problem is. 

{
"fields": {
"project": {
"key": "QLSIVMEA"
},
"summary": "[Re-Test] - MEM - Case ID: 95",
"reporter": {
"name": "testuser"
},
"description": "An Issue Re-Test request has been raised",
"labels": [
"Category=Re-Test",
"Source=NetSPI"
],
"customfield_18680": {
"value": "Re-Test"
},
"customfield_34881": {
"value": "NetSPI"
}
}
}

Yakov Borukhov July 27, 2021

is it possible that i dont have enough permissions to set the reporter of the jira or that specific project key doesnt allow a reporter to be set? That would answer all my questions

David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2021

Hello @Yakov Borukhov 

Yes, it's highly likely that the account you're using via the REST API to create the issue doesn't have permission to assign the reporter for issues in that project. Use those credentials to log into that project via the web and see if you can create a new issue and set the reporter as someone else.

If you don't set the reporter for an issue when you create it, either via the web UI or via the REST API, Jira will default to setting the reporter as being the person who created the issue.... which will be you, and you will see that for all the issues you have created so far via the REST API.

Even if you don't have permission to set a reporter for an issue in a project, if you have permission to create an issue in that project, then you should be able to set the assignee:

"assignee": {
    "name": "testuser"
},

You can also set the assignee for an issue after you've created it by dong a PUT request to the issue assign endpoint:

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

{
    "name": "testuser"
}

Like Yakov Borukhov likes this
Yakov Borukhov July 27, 2021

Interesting enough, i was also trying to set an assignee this exact way previously and was unsuccessful. But thanks to your advice, i logged in with my account and manually tried creating a jira. That jira key apparently limits who the assignee can be and doesnt even give an option for reporter. I was able to create a jira using the api with a specific user who is able to be the assignee just as a sanity check.

Thank you for enlightening me with your advice. This was a huge headache. You really cleared things up.

David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2021

Glad that you worked it out. If in doubt about permissions to do something with the REST API, always test the action with the web UI first, as the two systems use the same permissions to do the same actions.

A project that has the reporter field hidden from the web UI is fairly rare; it's almost always visible for most use cases. Whoever created that project and set it up that way must have had a very special reason for doing so. Perhaps the idea was to make the person who created the issue as the person responsible for it? Perhaps that only applies for some issue types, like bugs, but not others like stories or epics? Maybe that project uses only one issue type and that issue type has that special configuration?

However, even if the reporter field has been hidden from view on the web UI for a particular issue type, it's still there in the background, as it's a required field and must have a value when the issue is created (refer to this prior article).

Like Yakov Borukhov likes this
Yakov Borukhov July 28, 2021

Just to clarify, in my case it's not possible to choose a reporter when creating a jira using the UI for this specific jira key. But after I create the jira, the reporter shows up and is defaulted to the one who created the jira, which is me, but im actually creating the report for someone else.

I guess when creating this JIRA key, the admins didnt think that someone else would be creating jiras for other people. 

David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 28, 2021

Ahh, OK, that's different. The reporter field is just hidden unless it has a value. That makes more sense than totally hiding the field.

Suggest an answer

Log in or Sign up to answer