0

I am trying to use the ServiceNow API for the first time and I need to get a list of all the users in the sys_user table with all of their available fields/attributes like date created, updated etc.

I tried GET request to this URI: https://myinstance.service-now.com/api/now/table/sys_user

But the response only returns the Users and some of their attributes but not all of the ones I can see in the portal.

What is the correct URI to make the REST call to get all users and their fields/attributes?

robliv
  • 1,351
  • 3
  • 15
  • 30

2 Answers2

1

I'm assuming you want to access SN API from another application? Cause if you want to do that from within SN, there is the GlideRecord server API you can use.

Now when you access the table API from external source, you do that through a registered user - depending on this user and their roles, you might see all or only some of the user attributes. Also, if you add specific Query Parameters to your request like sysparm_query or sysparm_fields, this will limit what you get.

ACLs (Access Control Lists) is the mechanism in ServiceNow restricting access to Table API. So I would encourage you to check there. Perhaps you will need to create a technical user with sufficient roles to access the data you need.

Also the REST API Explorer which is found in SN Navigator can be of help to quickly test your table queries.

Hope that helps a bit!

TomaszS
  • 153
  • 1
  • 1
  • 6
  • Hi, thanks for the input, I appreciate it. I am querying it using a PowerShell script. The issue is I can get the individual attribute fields if I specify them using `sysparm_fields`. But if I don't specify them the API query only returns like 8 fields when there are over 30 in total. I would like to get all of them without mentioning their names in the API query. – robliv Mar 16 '20 at 21:03
  • Interesting. Have you tried running the same request using e.g. Postman or SN API Explorer? Are the results different then? One more thing to check is that perhaps it is returning the default View. If you don't want to expose field names in the request, you can create a specific view and then use the sysparm_view parameter in your request. – TomaszS Mar 17 '20 at 08:41
  • Hi, thanks a lot, I forgot to answer before, but this turned out to be a permission issue. Marked as answer. – robliv May 26 '20 at 13:05
  • @robliv what was the permission? – rafasalo Dec 08 '22 at 11:33
1

In general table api returns all the columns associated to the table unless until if you have specified the specific column list in sysparam_fields, can you please try in post man or try the same api call from rest api explorer in Servicenow to understand the behavior. H

Chandran
  • 11
  • 2
  • Hi, thanks for the input, this was a few months ago, I ended up realizing there is a permission issue for the user I was using to run the job with. I was confused since when querying initialy what was returned was a mix of filled and empty fields and some fields that I saw in portal were missing, which lead me to think I have the wrong query instead of missing permissions. – robliv May 26 '20 at 13:04
  • @robliv What permission was missing? I have the same issue here – rafasalo Dec 08 '22 at 11:32
  • @rafasalo Hi, honestly I don't remember, that was almost 3 years ago. And in my case it was a different team that manages these permissions. I assume it was ACL rule for read_only access for my user/role to the specific table or all tables. Maybe this helps https://docs.servicenow.com/en-US/bundle/tokyo-platform-administration/page/administer/contextual-security/concept/access-control-rules.html – robliv Dec 09 '22 at 12:20