creating a sys_user using rest api call

Deepali5
Tera Contributor

I want to create a new login user using rest API.

I can post to sys_user table right?

I see that sys_user table has a role field. How can I assign multiple roles while creating the user. I tried to put a comma separated list as a value for the role field. e.g

{"first_name":"xx","last_name":"yy","company":"Aa","roles":"admin,user","user_name":"superuser"}

The response shows success but in the actual user record I don't see any roles assigned. 

So how do I assign roles thr' rest API

I also want add user to a group.

Do I need to write a separate rest call to sys_user_group to create a group? 

Thanks

 

9 REPLIES 9

Without using import/transform you are limited to adding a single record\relationship per payload and will need to use the sys_id of the role, not the name of the role.

Thanks @Tony Chatfield1 

I think I am able to assign admin role to the user I am creating. But I still can  not login using this newly created user. I get error as username or password invalid. Also when I try to make any other rest API call using the username/password I newly created, I get 401 error.

So I think password is not getting set for this user. Can I see password field in the user record in servicenow UI to check if it is correct ?

Thank you

@Deepali5 ,

 

I have answered the same question in this Thread , Please take a look and accept it if it works for you!

The password field is 1 way encrypted and so you cannot see if it is correct, but you can test the account by trying to login using a different browser or an incognito\private window.

Deepali5
Tera Contributor

I think I may need to crate a role record using sys_user_role? But I can access that table from rest api explorer?

How do I enable sys_user_role?

Thank you