Example of using the instances REST API to search for CIs


Allen Allbrook, a CMDB configuration manager with Calbro Software Services wants to view all printers in the production dataset.

He uses the following REST API:

/cmdb/v1.0/instances/{datasetId}/{namespace}/{className}

The following example represents a sample request and its response for Allen's requirement: 

Sample Request

/api/cmdb/v1.0/instances/BMC.ASSET/BMC.CORE/BMC_ComputerSystem?num_matches=true&qualification='ClassId' LIKE "BMC_PRINTER%25"&limit=10&offset=0&attributes=row_details_column,Name,ClassId,DatasetId,InstanceId,ShortDescription,ClassId

Important

Sometimes, the wildcard % in the query might not work as expected. In such cases, use the wildcard combination of %25.

For example, /api/cmdb/v1.0/instances/BMC.ASSET/BMC.CORE/BMC_ComputerSystem?num_matches=true&qualification='ClassId' LIKE "BMC_Printer%25"&limit=10&offset=0&attributes=Name,ClassId,DatasetId,InstanceId,ShortDescription

Sample Response

Response
  {
   "instances": [
       {
           "instance_id": "OI-BE3EFE420DA211EDA5EC57F0933CC4F0",
           "class_name_key": {
               "name": "BMC_ComputerSystem",
               "namespace": "BMC.CORE"
           },
           "dataset_id": "BMC.ASSET",
           "attributes": {
               "InstanceId": "OI-BE3EFE420DA211EDA5EC57F0933CC4F0",
               "ClassId": "BMC_PRINTER",
               "Name": "Color Laser Jet b65b5a0c-e743-469b-9055-be36848c25a3",
               "DatasetId": "BMC.ASSET",
               "ShortDescription": "Wed Jul 27 14:57:50 IST 2022 performance testing "
           },
           "_links": {
               "self": [
                   {
                       "href": http://clm-pun-vhl7f0.bmc.com:8008/api/cmdb/v1.0/instances/BMC.ASSET/BMC.CORE/BMC_ComputerSystem/OI-BE3EFE420DA211EDA5EC57F0933CC4F0
                   }
                ]
           }
       },
       {
           "instance_id": "OI-BE3CBECA0DA211EDA5DA57F0933CC4F0",
           "class_name_key": {
               "name": "BMC_ComputerSystem",
               "namespace": "BMC.CORE"
           },
           "dataset_id": "BMC.ASSET",
           "attributes": {
               "InstanceId": "OI-BE3CBECA0DA211EDA5DA57F0933CC4F0",
               "ClassId": "BMC_PRINTER",
               "Name": "Color Laser Jet 1a58e18c-b4b4-4709-a54a-7cbd9f5615e1",
               "DatasetId": "BMC.ASSET",
               "ShortDescription": "Wed Jul 27 15:07:24 IST 2022 performance testing "
           },
           "_links": {
               "self": [
                   {
                       "href": http://clm-pun-vhl7f0.bmc.com:8008/api/cmdb/v1.0/instances/BMC.ASSET/BMC.CORE/BMC_ComputerSystem/OI-BE3CBECA0DA211EDA5DA57F0933CC4F0
                   }
                ]
           }
       },
       {
           "instance_id": "OI-BE4ECEA80DA211EDA63E57F0933CC4F0",
           "class_name_key": {
               "name": "BMC_ComputerSystem",
               "namespace": "BMC.CORE"
           },
           "dataset_id": "BMC.ASSET",
           "attributes": {
               "InstanceId": "OI-BE4ECEA80DA211EDA63E57F0933CC4F0",
               "ClassId": "BMC_PRINTER",
               "Name": "Color Laser Jet 3d70270c-980b-4275-a367-1d07617b951b",
               "DatasetId": "BMC.ASSET",
               "ShortDescription": "Wed Jul 27 14:59:36 IST 2022 performance testing "
           },
           "_links": {
               "self": [
                   {
                       "href": http://clm-pun-vhl7f0.bmc.com:8008/api/cmdb/v1.0/instances/BMC.ASSET/BMC.CORE/BMC_ComputerSystem/OI-BE4ECEA80DA211EDA63E57F0933CC4F0
                   }
                ]
           }
       },
       {
           "instance_id": "OI-BE59C9AC0DA211EDA67057F0933CC4F0",
           "class_name_key": {
               "name": "BMC_ComputerSystem",
               "namespace": "BMC.CORE"
           },
           "dataset_id": "BMC.ASSET",
           "attributes": {
               "InstanceId": "OI-BE59C9AC0DA211EDA67057F0933CC4F0",
               "ClassId": "BMC_PRINTER",
               "Name": "Color Laser Jet 0021911a-2797-4562-86af-fe089cdcded4",
               "DatasetId": "BMC.ASSET",
               "ShortDescription": "Wed Jul 27 14:59:54 IST 2022 performance testing "
           },
           "_links": {
               "self": [
                   {
                       "href": http://clm-pun-vhl7f0.bmc.com:8008/api/cmdb/v1.0/instances/BMC.ASSET/BMC.CORE/BMC_ComputerSystem/OI-BE59C9AC0DA211EDA67057F0933CC4F0
                   }
                ]
           }
       },
       {
           "instance_id": "OI-BE66D3FE0DA211EDA6A257F0933CC4F0",
           "class_name_key": {
               "name": "BMC_ComputerSystem",
               "namespace": "BMC.CORE"
           },
           "dataset_id": "BMC.ASSET",
           "attributes": {
               "InstanceId": "OI-BE66D3FE0DA211EDA6A257F0933CC4F0",
               "ClassId": "BMC_PRINTER",
               "Name": "Color Laser Jet 81bae292-4093-48eb-aa31-2d272b5021a3",
               "DatasetId": "BMC.ASSET",
               "ShortDescription": "Wed Jul 27 14:51:36 IST 2022 performance testing "
           },
           "_links": {
               "self": [
                   {
                       "href": http://clm-pun-vhl7f0.bmc.com:8008/api/cmdb/v1.0/instances/BMC.ASSET/BMC.CORE/BMC_ComputerSystem/OI-BE66D3FE0DA211EDA6A257F0933CC4F0
                   }
                ]
           }
       },
       {
           "instance_id": "OI-BE7BC7640DA211EDA6D457F0933CC4F0",
           "class_name_key": {
               "name": "BMC_ComputerSystem",
               "namespace": "BMC.CORE"
           },
           "dataset_id": "BMC.ASSET",
           "attributes": {
               "InstanceId": "OI-BE7BC7640DA211EDA6D457F0933CC4F0",
               "ClassId": "BMC_PRINTER",
               "Name": "Color Laser Jet eeea2404-bb77-46d2-8857-86c15274c9f0",
               "DatasetId": "BMC.ASSET",
               "ShortDescription": "Wed Jul 27 15:00:08 IST 2022 performance testing "
           },
           "_links": {
               "self": [
                   {
                       "href": http://clm-pun-vhl7f0.bmc.com:8008/api/cmdb/v1.0/instances/BMC.ASSET/BMC.CORE/BMC_ComputerSystem/OI-BE7BC7640DA211EDA6D457F0933CC4F0
                   }
                ]
           }
       },
       {
           "instance_id": "OI-BE9297D20DA211EDA70657F0933CC4F0",
           "class_name_key": {
               "name": "BMC_ComputerSystem",
               "namespace": "BMC.CORE"
           },
           "dataset_id": "BMC.ASSET",
           "attributes": {
               "InstanceId": "OI-BE9297D20DA211EDA70657F0933CC4F0",
               "ClassId": "BMC_PRINTER",
               "Name": "Color Laser Jet ae508fa3-b00d-46c6-8ced-8acbedf57f82",
               "DatasetId": "BMC.ASSET",
               "ShortDescription": "Wed Jul 27 14:54:50 IST 2022 performance testing "
           },
           "_links": {
               "self": [
                   {
                       "href": http://clm-pun-vhl7f0.bmc.com:8008/api/cmdb/v1.0/instances/BMC.ASSET/BMC.CORE/BMC_ComputerSystem/OI-BE9297D20DA211EDA70657F0933CC4F0
                   }
                ]
           }
       },
       {
           "instance_id": "OI-BE3CC6680DA211EDA5DB57F0933CC4F0",
           "class_name_key": {
               "name": "BMC_ComputerSystem",
               "namespace": "BMC.CORE"
           },
           "dataset_id": "BMC.ASSET",
           "attributes": {
               "InstanceId": "OI-BE3CC6680DA211EDA5DB57F0933CC4F0",
               "ClassId": "BMC_PRINTER",
               "Name": "Color Laser Jet 5a405e85-1cc9-44e3-9290-0c4587759243",
               "DatasetId": "BMC.ASSET",
               "ShortDescription": "Wed Jul 27 15:02:49 IST 2022 performance testing "
           },
           "_links": {
               "self": [
                   {
                       "href": http://clm-pun-vhl7f0.bmc.com:8008/api/cmdb/v1.0/instances/BMC.ASSET/BMC.CORE/BMC_ComputerSystem/OI-BE3CC6680DA211EDA5DB57F0933CC4F0
                   }
                ]
           }
       },
       {
           "instance_id": "OI-BE66DADE0DA211EDA6A357F0933CC4F0",
           "class_name_key": {
               "name": "BMC_ComputerSystem",
               "namespace": "BMC.CORE"
           },
           "dataset_id": "BMC.ASSET",
           "attributes": {
               "InstanceId": "OI-BE66DADE0DA211EDA6A357F0933CC4F0",
               "ClassId": "BMC_PRINTER",
               "Name": "Color Laser Jet 697ae80f-3407-4523-9019-a6642370dd59",
               "DatasetId": "BMC.ASSET",
               "ShortDescription": "Wed Jul 27 15:00:04 IST 2022 performance testing "
           },
           "_links": {
               "self": [
                   {
                       "href": http://clm-pun-vhl7f0.bmc.com:8008/api/cmdb/v1.0/instances/BMC.ASSET/BMC.CORE/BMC_ComputerSystem/OI-BE66DADE0DA211EDA6A357F0933CC4F0
                   }
                ]
           }
       },
       {
           "instance_id": "OI-BE59D12C0DA211EDA67157F0933CC4F0",
           "class_name_key": {
               "name": "BMC_ComputerSystem",
               "namespace": "BMC.CORE"
           },
           "dataset_id": "BMC.ASSET",
           "attributes": {
               "InstanceId": "OI-BE59D12C0DA211EDA67157F0933CC4F0",
               "ClassId": "BMC_PRINTER",
               "Name": "Color Laser Jet e4d1f9c6-318b-448d-ad45-4a483c224947",
               "DatasetId": "BMC.ASSET",
               "ShortDescription": "Wed Jul 27 15:10:11 IST 2022 performance testing "
           },
           "_links": {
               "self": [
                   {
                       "href": http://clm-pun-vhl7f0.bmc.com:8008/api/cmdb/v1.0/instances/BMC.ASSET/BMC.CORE/BMC_ComputerSystem/OI-BE59D12C0DA211EDA67157F0933CC4F0
                   }
                ]
           }
       }
    ],
   "num_matches": 6454
}

Do you want to learn more?

Learn about more things you can do with the REST API in Endpoints-in-the-REST-API.

 

 

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*