Can you use an API to pull data from a CMDB Query builder query?

wheels
Tera Contributor

We would like to extract relationship data from the CMDB using an API. The best way I can think of is to create a query using the CMDB query builder and if possible run the query using an API. I have searched and can find no information on whether this is possible.

4 REPLIES 4

Jayant Kaushal
ServiceNow Employee
ServiceNow Employee

Yes, you can use table apis in case you want to know attributes of a specific CI,

https://docs.servicenow.com/integrate/inbound_rest/concept/c_TableAPI.html

 

In case you need to find the relationships , it becomes little tricky but you can query cmdb_rel_ci and find the right CI.

https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/product/configuration-management...

 

Also, you can use Identification and Reconciliation APIs to fetch the data through REST,

https://docs.servicenow.com/bundle/helsinki-servicenow-platform/page/integrate/inbound-rest/concept/...

 

 

Thanks Jayant, reconstructing the query by using the cmdb_rel_ci table is too complex and hence this is one of the reason ServiceNow has introduced the Query Builder. Having said that, I think you might be onto something as i think the query builder outputs to tables that we could possibly use 

https://docs.servicenow.com/integrate/inbound_rest/concept/c_TableAPI.html

 

I am not sure how the last option would help and would need to explore that. 

Thanks again for your reply 

I just started looking into doing the same. Were you able to accomplish this? (retrieving data from a saved query using the API) 

Constantine Kr1
Giga Guru

There is an API that will generate a temporary table of results, and provide a JSON object on how to access the report. 

Please see the CMDBQueryBuilderAPI documentation: 

https://docs.servicenow.com/bundle/rome-application-development/page/app-store/dev_portal/API_refere...

Attached is an example: 

var result = SNC.CMDBQueryBuilderAPI.getSavedQueryExecutionDetails("QueryBuilderReportName", true);
gs.info(result);

// var result = 
// { "execution_batch_size":100,
//   "query_id":"aabb556671baabb506d66777fdc4142321",
//   "table_name":"u_cmdb_qb_result_791ccddeeff7a168bb1122334455688778899ab143aabb666",
//   "status":"COMPLETE"
//  }

The report data can be accessed from the "table_name" property of the JSON object and will be stored in the following table: 

u_cmdb_qb_result_791ccddeeff7a168bb1122334455688778899ab143aabb666

Thanks,
~CK