I’m trying to use the api “/rest/api/3/user/search?query”, but I fail to make it working using a “displayname” as a query.
I’m trying to find the accountId of the account “Automation for Jira”
It’s ok if i use the query
“/rest/api/3/user/search?query=automation”
but if i use the query
“/rest/api/3/user/search?query=automation for jira”
it returns all users containing either “for” or “jira” in any field !
How can I do an exact match on displayname ?
I’ve also tried several requests , but it doesn’t work :
/rest/api/3/user/search?query=displayName:automation for jira
/rest/api/3/user/search?query=displayName:automation%20for%20jira
What you are observing is the expected behaviour of that endpoint. It can’t search for displayName using spaces, only the first part of the string, the prefix. This is described in the documentation where it says:
The string can match the prefix of the attribute’s value. For example, query=john matches a user with a displayName of John Smith
So, unless you have multiple users with display names that start with ‘automation’, then it’s not a problem. If you do have multiple users with display names that start with ‘automation’, then you will have to filter the results returned in your code.
I could be wrong but I think the accountId for ‘Automation for Jira’
is the same across all Atlassian instances so as a hack (not actually suggesting you do this) you could just hardcode in 557058:f58131cb-b67d-43c7-b30d-6b58d40bd077.