Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get only the support groups from 'cmdb_ci_service' table through REST API?

User205031
Tera Contributor

Hi All,

 

I want to get only the support groups from 'cmdb_ci_service' table through REST API. 

User205031_0-1763960152853.png

 

Getting response as :

User205031_1-1763960202786.png

I am getting multiple records with same Support group name, but I want to display only unique values.

 

How can we achieve this? 

1 REPLY 1

Vishal_Jaiswal
Mega Guru

Hi @User205031 ,

 

- The standard Table API (which you are currently using) returns individual records. It does not natively support "DISTINCT" or "Unique" operations to filter out duplicates on the server side.
 
- To achieve this without writing a custom script, you should use the Stats (Aggregate) API. This API is designed specifically to group records and return unique values.
 
- Here is how to configure your request to get unique Support Groups:
Solution: Use the Stats API
Change your endpoint from /table/ to /stats/ and use the sysparm_group_by parameter.
 
1. The Request URL Change your URL structure to: GET https://instance.service-now.com/api/now/stats/cmdb_ci_service
2. The Parameters In your REST API Explorer (or your code), configure the parameters as follows:
- sysparm_query: support_group.nameSTARTSWITHNetwork (Keep your existing filter)
- sysparm_group_by: support_group.name (This is the magic parameter that groups duplicates into a single entry)
- sysparm_count: true (This tells the system to just return the groupings)
 
Regards,
Vishal