REST API - Get all roles for user

J_ Greene
Kilo Expert

I am trying to get a list of all roles a single user is assigned, however, this query doesn't appear to work

https://<instance>/api/now/table/sys_user_has_role?sysparam_query=user.value=<sys_id>

...It returns the entire table

Thoughts?

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

Can you try with below url

 

https://<instance ID>.service-now.com/api/now/table/sys_user_has_role?sysparm_query=user%3Dd3dbbf173b331300ad3cc9bb34efc466&sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_fields=role

View solution in original post

4 REPLIES 4

Harsh Vardhan
Giga Patron

Can you try with below url

 

https://<instance ID>.service-now.com/api/now/table/sys_user_has_role?sysparm_query=user%3Dd3dbbf173b331300ad3cc9bb34efc466&sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_fields=role

Note: change the user sys_id, 

I am assuming you are looking for role field value .

 

Screenshot for your reference:

 

 

find_real_file.png

 

 

Thanks - I tested this on a single user sys_id, and it returned 10,000 results, however, the user sys_id only had 68 roles assigned to it. So it seems as though the query is not working as expected.

Thoughts?

Kieran Anson
Kilo Patron

Hi, you've declared "user.value" which would be an invalid query so the entire table will be returned. Your query should be 

https://<instance>/api/now/table/sys_user_has_role?sysparam_query=user=<sys_id>

Alternatively you can use the /global/user_role_inheritance if you want to see more of a inheritance map view.