need unique list of ServiceNow CMDB sys_class_names via REST API

shafeeqrafeek
Tera Contributor

I need to get the unique list of sys_class_names from ServiceNow CMDB. I used the below api call but here it returns duplicate values and also extremely slow. 

 

https://instance.service-now.com/api/now/table/cmdb_ci?sysparm_fields=sys_class_name

2 REPLIES 2

Weird
Mega Sage

Well, you're querying the whole cmdb_ci table for all the records in there and just returning the sys_class_name field value of each record.

You could try querying sys_db_object table with query "nameLIKEcmdb_ci" then set name as the sysparm_fields value.

/api/now/table/sys_db_object?sysparm_query=nameLIKEcmdb_ci&sysparm_fields=name



Technically you'd get more that you want, but it's kinda close.
Another option would be to build your own scripted rest api. Can't say what would be the best way to query the classess, but you could at least use GlideAggregate to get the class names faster from the cmdb_ci table.

Other than that I'm not sure if there's a good way to directly get just each available class (table) faster.

Community Alums
Not applicable

Hi @shafeeqrafeek ,

 

Like @Weird suggested you could update your query using name or add few more conditions to minimise the count.

 

But, I would suggest that you go for a Scripted REST API which could help you add query & get the required fields data instead of pulling the data from whole table. 

 

Please mark it as "Accept as Solution" and " Helpful. if this solution helped you.


Thanks & Regards,
Madhan Somesh.