Is there a way to do a 'like' query using the REST API?

jimdawson
Giga Contributor

I'm trying to create a REST GET query using the sysparm_query parameter matching a subset of a field name, e.g.

https://MyInstance.service-now.com/api/now/table/cmdb_ci_server?sysparm_fields=name,os&sysparm_query...

to match all records in cmdb_ci_server where the OS has 'Windows' in it. Obviously this doesn't work.

However, if I search for the full name, e.g.

...&os=Windows 2012 Datacenter

it matches correctly, but in this case I'm trying to match all versions of Windows.

Is there a way to do this? Or would I better off to pull down all records and filter them client side?

Thanks.

1 ACCEPTED SOLUTION

Also, cmdb_ci_server?sysparm_query=osLIKEwindows worked.


View solution in original post

6 REPLIES 6

I have found a couple of caveats to using Copy Query to generate URLs for use with cURL:



  • Any spaces in the query string must be converted to '%20'
  • Some extended properties are collapsed in the Service Now web interface and need to be expanded to the fully qualified field name. i.e. 'Manufacturer' needs to be expanded to 'manufacturer.name'


But this allowed me to condense a 50 line Powershell script into a 1 line cURL statement.


Nevermind, Figured out that 'osCONTAINSWindows^cpu_nameCONTAINSamd' works.