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

@Prince Arora 

Great! It worked. Thanks,  I can see the encrypted password in the response. and I could login locally.
Can I do the same to assign admin and user roles to this user using sys_user_has_role table and 

payload = {
"role": "admin,user,activity_admin",
"user": user_sys_id of the record just created
}
Thanks again

@Deepali5 ,

 

You marked my answer as helpful!

Please accept the solution if it has worked for you, it would be beneficial for future readers

I marked Accept as solution.

I had another question about assigning admin and user roles to this user using sys_user_has_role table.

I am using 

payload = {"role": "sn_hr_sp.esc_admin",
"user": user_sys_id}
This works, But I need to add more roles like admin_activity , user etc.
Could you shed light on how I can assign multiple roles admin_activity , user ?
Thank you

@Deepali5 ,

 

Give me sometime will definitely answer your question 🙂

@Deepali5 ,

 

I have checked the API and it seems that we can add a single role at a time using the Rest API

I would suggest create a custom role in the instance and add all the required roles which you want to add in that and by making rest API call you can assign custom role to the user, it will reflect all the roles to the user automatically!

 

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