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

Mike Allen
Mega Sage

cmdb_ci_server?sysparm_query=osCONTAINSwindows



Gave me 19 results in PowerShell.   I went into the table in the application and, sure enough, I had 19 servers that osCONTAINSwindows.


Also, cmdb_ci_server?sysparm_query=osLIKEwindows worked.


This works, thanks!



Only problem is I can't figure out how to do multiple queries, e.g. 'osCONTAINSWindows&cpu_nameCONTAINSamd'


I can do a simple equals, e.g. 'osCONTAINSWindows&cpu_count=2' but I can't figure out how to do multiple CONTAINS or LIKE filters.



Do you know if there is any better documentation on constructing REST queries than the 'Table API' document?


There is stuff on the developers site: ServiceNow Developers



Maybe something is different here in Geneva-docs: Table API



The best way to construct your query, though, is to go in the tool and construct it in the application.



find_real_file.png



find_real_file.png



find_real_file.png