can not login using credentials I created thr' rest API

Deepali5
Tera Contributor

I created a user using rest api posting to sys_user

I gave username and password

payload = {"first_name": "Dummy",
"last_name": "User",
"user_name": "user1",
"user_password": "<Somepassword>"
}
I got success response 201
I also assigned admin role to this user.
I can see this user record being created in servicenow.
but if I logout from admin and try to login into servicenow as this new user1, using the credentials I created, I
get error as username or password is incorrect
 
I am trying do a third party integration with servicenow, for that I need to create my own user and the integrate into incidents.
I want to automate the whole process including creating user. I am just testing right now with rest explorer.
Will look into creating imports/transform later.
 
How do I know if password is set correctly? If not how to set the password thr' post rest API call?
 
Thank you
1 ACCEPTED SOLUTION

Prince Arora
Tera Sage
Tera Sage

@Deepali5 ,

 

I have tried this in my PDI and worked really well for me!

 

Could you please try this, I have used the same body which you mentioned 

 

You are going in the right direction, can you make "sysparm_input_display_value" to true as mentioned in the screenshot.

 

PrinceArora_0-1681365852220.png

 

PrinceArora_1-1681365918867.png

 

After creation of user, I was able to login with the user_name and password!

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

 

 

 

 

View solution in original post

10 REPLIES 10

Hi @Prince Arora ,

I created a sys_user_role object using url and payload

url = table_url + 'sys_user_role?sysparm_input_display_value=true'
payload = {"role": "admin",
                   "name": "myRole"
                 }
I got success it generates a role object but it does not contain any roles/permissions assigned.
Then I used the sys_id of this role object created in next call to 
url = table_url + 'sys_user_has_role'
payload = {"role": role_sys_id,
                   "user": user_sys_id}
But it does not work. The user gets a role object assigned with name as myRole but that does not contain any of the permissions that are usually generated.
 
I don't know if the payload I am using to create sys_user_role in first step above is correct because I don't see that table in rest API explorer to test it out. 
 
Any ideas?
Thanks