How I can create new user in service now using rest API and assing him a role?

dougoutigi
Mega Contributor

Hello,

I need help please

How I can create new user in service now using rest API and assing   him a role?

If possible an example will be   helpful

Thank you

1 ACCEPTED SOLUTION

Hi Alassane,



If you have the endpoint of the post method from this form you can use that and consume the REST service in your java code like any other rest webservice by passing the variables like in any other REST webservice.



Moreover, you can refer this page as well.


Table API Java Examples - ServiceNow Wiki



Hope it helps.



Thanks and Regards,


Vikas Malhotra


View solution in original post

11 REPLIES 11

dougoutigi
Mega Contributor

Hi Viskas,


Thanks for your answer


I saw   this link. I need more detail.How I can use the table "sys_user " to create and the table "sys_user_has_role" to assing him a role?


Hi Alassane,



Please go to REST API Explorer. There you will find a form like this:


API Exploere.PNG


Here you can select the name of table like "sys_user" in thsi case and post method to insert a record (on the left side in blue). Then below you will find the request body tab here you can add the fields and their values.


Something like this:




and then click send.



New user will be created same is with sys_user_has_role.


API 2.PNG


Hope its helpful.



Thanks and Regards,


Vikas Malhotra


dougoutigi
Mega Contributor

Hi Vikas,


I want to create user and assing him a role using REST API in java from Eclipse. After doing that you explain me above. How I can use it in my java code?


Thank you for your answer