I am trying to search user by e-mail address. I am using:
def userResult = get("/rest/api/2/user/search?username=hello@gmail.com")
.header('Content-Type', 'application/json')
.asObject(Map)
if (userResult.status == 200) {
return userResult.body.fields
}
else {
return "result.status"
}
I get this response:
"Cannot get property 'fields' on null object"
I tried with each user, email and username and nothing changes.
Thank you for your help
Hi Constance,
Thank you for your question.
Further to my previous reply I believe that if you made the following changes below to your script then it should work.
If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.
Regards,
Kristian
Thank you Kristian for your help!
Do you think you can help me get only the "name" element instead of the entire body? :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can just change the return line to be 'return userResult.body.name' to get just the name element out of the body.
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.
Hi Constance,
Thank you for your question.
I can confirm that to search for a user you need to use the Get user rest API described here rather than the search api.
I have created an example script located here which can be ran from the script console to return a user based on a specified username and you can modify this example to suit your needs.
Please note the Get user API does not permit searching on an email address and as stated in the documentation only permits searching for a user using the username or user key.
If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.