how to create new user in service now using rest API and assing admin role to him?

thiyagarajan1
Kilo Contributor

Hi Friends,

I want to create a new user in service now by using REST API with the specified user role to the user.

my input is given below,

{"user_name":"maheswar","first_name":"Shiv","last_name":"Maheswar","title":"Administrative Assistant","department":"Development","user_password":"mypassword","active":"true","email":"abc@gmail.com","mobile_phone":"958747845",

"roles":"rest_service,web_service_admin,admin"}

the user is created but no userrole assign to him

is my input assignment is wrong - "roles":"rest_service,web_service_admin,admin" ?

please any help me on this.

Regards,

Thiyagu

1 ACCEPTED SOLUTION

sach1
Tera Guru

Hi Thiyagarajan,



User records are present in 'sys_user' table, I assume your rest wsdl is pointing to this table.



A separate table "sys_user_has_role" has the records for roles associated to any user.



While creating the user using REST API you will also have to create record in "sys_user_has_role" table for that user with the desired role. Hope this helps.


View solution in original post

13 REPLIES 13

Subhajit1
Giga Guru

You will have to keep 2 things in mind:-


1. While creating the User record, your target table is sys_user but when assigning a new role, the target table has to be sys_user_has_role.


2. The User profile that is being used to authenticate the incoming rest message needs to have Admin role as well if it has to add the Admin role to someone else.


Hi



yes, add user rest wsdl is pointing to this table sys_user.



Can you give me the add role to that user API code sample?



Regards,


Thiyagu


The Target table would be sys_user_has_role and it takes two important parameters, User and Role, so you will have to send individual triggers for individual roles with the User and Role information.


The User profile that is being used to authenticate the incoming rest message needs to have Admin role as well if it has to add the Admin role to someone else.


This is incredibly dangerous, and I'd wonder where there are situations in which a quick incoming REST packet has the ability to create such privileged users.