How to get a single value using REST API?

santrym
Mega Expert

I want the sys_id from a single row from the user table using the REST API. I don't want to go through the effort of creating a java object, creating the object (Json -> java), then retrieving the value. Is there a way to query so that I only get the sys_id returned?

What I have thus far:

        "https://myCompany.service-now.com/api/now/table/sys_user?user_name=" + username

4 REPLIES 4

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

If you are on the Geneva release, a scripted REST would allow you to do this:


https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/integrate/custom_web_services/c...



You could pass in just the username and then you can control the response back too.


We're still on Fuji unfortunately...


Bummer, you could do it with SOAP in Fuji but Geneva introduces scripted REST.


Chuck Tomasi
Tera Patron

Have you thought about using sysparm_query to get the single record (based on employee ID or something) and then sysparm_fields to return just the sys_id? Something like this (only I queried on the name field)



https://yoursite.service-now.com/api/now/table/sys_user?sysparm_limit=10&sysparm_query=name=Abel Tuter&sysparm_fields=sys_id



The result was:




{
  "result": [
  {
  "sys_id": "62826bf03710200044e0bfc8bcbe5df1"
  }
  ]
}



Use the REST API explorer to craft your REST request. Links near the SEND button will give you code snippets for ServiceNow (JavaScript), cURL, Python, Ruby, etc.



find_real_file.png