REST API Query JSON Sub-Object

seannilsen
Kilo Explorer

Hi All,

I am trying to query the Incidents table using the REST API based on the caller_id.value.

I already have the sys_user's sys_id from a previous lookup, which works fine, and I want to grab the JSON Array of incidents that the user has opened.

In the JSON response for a generic Incident I can see this for the caller_id:

  ...

  "caller_id": {
  "link": "https://dev18522.service-now.com/api/now/table/sys_user/5137153cc611227c000bbd1bd8cd2005",
  "value": "5137153cc611227c000bbd1bd8cd2005"
  },
  "resolved_at": "2016-08-13 19:56:12",
  "approval_set": "",
  "subcategory": "",

    ...

But when I query for caller_id.value=5137153cc611227c000bbd1bd8cd2005 (or some other sys_user's sys_id)

The response comes back with all open Incidents, indicating that it was a zero match to my original query.

The API Docs don't really say (that I could find) how to query sub-object fields but I've tried dot notation and other methods, but can't seem to find the right way to get after this.

Can someone provide an answer to this? Or is there a different approach to using the User's sys_id for querying for Incident's that I haven't considered?

Thanks!

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Sean,



Your URI will have to include something like this:



sysparm_query=caller_id=5137153cc611227c000bbd1bd8cd2005



Getting Started with REST - ServiceNow Wiki


REST API Explorer - ServiceNow Wiki


REST API  


View solution in original post

3 REPLIES 3

Chuck Tomasi
Tera Patron

Hi Sean,



Your URI will have to include something like this:



sysparm_query=caller_id=5137153cc611227c000bbd1bd8cd2005



Getting Started with REST - ServiceNow Wiki


REST API Explorer - ServiceNow Wiki


REST API  


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Sean,



Just to add to Chuck's answer, when you write your queries you don't have to write them with the json object that gets returned in mind, just use standard ServiceNow encoded querying. Here are some links, but the first one will help you generate your queries to use in your REST call.



Generate an encoded query string through a filter


Encoded query strings


URL schema  


Much appreciated!



The pointers and the callout to thinking in ServiceNow terms instead of straight up SOA terms are helpful.



I am also thinking that feedback to the documentation folks on the ServiceNow side is that "Copy the query from the breadcrumb" would be useful to call out in the documents someplace other than 4 layers deep in the "Lists" section.



Many thanks to you guys!