Share This:

Welcome to the new blog on BMC CMDB.   In our last blog, we focused on CMDB REST API with focus on using 'instance' CRUD operations.  Below is the link for that blog

 

https://communities.bmc.com/community/bmcdn/bmc_it_service_support/cmdb/blog/2020/05/29/helix-support-introduction-to-cmdb-rest-api-services-and-comparison-with-cmdbdriver-command-line-tool

 

This blog is a continuation to the previous one with a focus on 'Attribute' CRUD operations.  Hence, the topics covered in this blog are as follows:

 

[a] Get Attribute information from a class using GET method

[b] Create a single custom attribute in a class using POST method

[c] Create multiple custom attributes in a class using POST method

[d] Modify a single attribute in a class using PATCH method

[e] Delete a single attribute in a class using DELETE method

 

To begin with, I've used POSTMAN tool to perform the above mentioned operations.   POSTMAN tool  is easily available for downloading on the web.  Just a recap, to access the CMDB REST API services, we must first generate an authorization token by login to AR server.   Its simple, it is covered in my previous blog.  To generate a token, please launch the POSTMAN tool and click the NEW button to present a new Request page.  You shall use the login URL using POST method, and fill out the AR login credentials like below.  Once the authentication is successful, you shall see the authorization token.

 

Authorization.PNG

 

Authorization Token as  Header:  This token, as long as valid, can be reused for the consumption of several REST API services.  Below is a screenshot of how one can populate such a token under the Header section n when using any desired REST API services.  In all of the examples in this blog, you shall refer to the below screenshot to fill out Headers to the requests.

 

Using the Auth code.PNG

 

If you see an error message like HTTP 400 or Authentication Failed, this means the authorization token is invalid, and you may have to regenerate it.

 

Having done that, we can now proceed with consuming the REST API for CMDB class Attribute CRUD operations.

 

[a] Get information about CMDB class Attributes using GET method:

 

Method: GET

 

Request URLhttp://testserver:8008/cmdb/v1.0/attributes/{namespace}/{className}

 

[STEP 1] Create a new request in POSTMAN tool.  Select the method as 'GET'.   Type the URL in the following format considering your are pulling Attribute information from BMC_ComputerSystem class

 

Example: http://testserver:8008/cmdb/v1.0/attributes/BMC.CORE/BMC_ComputerSystem

 

[STEP 2]  Go to the Headers section and fill out the Authorization parameters like mentioned in the above picture 'Authorization token as Headers'

 

[STEP 3] Switch to the PARAMS tab and fill out the parameters as seen in the screenshot.    In the example below, I'm pulling information on two attributes of BMC_ComputerSystem class - 'HostName' and 'PrimaryCapability'.  As you add those parameters, you will notice the Request URL is being appended with querystring parameters.

 

Click SEND button when all the parameters are typed out.  The GET method will retrieve the specified attribute information.

 

 

1_GET_Attribute.PNG

 

 

[b] Create a single custom attribute in a class using POST method

 

METHOD:   POST

 

REQUEST URL: http://testserver:8008/api/cmdb/v1.0/attributes/namespace}/{className}/{attribute}

 

[STEP 1]  Create a new request in POSTMAN.  Select the method as 'POST'.   Type your REST API server URL in the following example format considering you are creating an Attribute named 'test31' in BMC_BaseElement class.

 

EXAMPLEhttp://testserver:8008/api/cmdb/v1.0/attributes/BMC.CORE/BMC_BaseElement/test31

 

[STEP 2] Go to the Headers section and fill out the Authorization parameters like mentioned in the above picture 'Authorization token as Headers' (coped at the beginning of this blog)

 

[STEP 3] Switch to the BODY tab, select 'raw' as an option and change the format (available as a drop-down) from Text to JSON;  Copy the below JSON content inside the BODY tab, and then click SEND button.

 

{

"datatype":"CHAR",

"name":"test31",

"type":"REGULAR",

"class_id":"BMC_ASSETBASE",

"class_name_key":{"namespace":"BMC.CORE","name":"BMC_BaseElement"},

"characteristics":{"NAMESPACE":"BMC.CORE","DESCRIPTION":"Test 24","AUDIT":"NONE","HIDDEN":false,"CREATE_MODE":"PROTECTED"},

"entry_mode":"OPTIONAL",

"field_id":"234328",

"limit":{"char_limit":{"max_length":255,"pattern":"","char_menu":"","menu_style":"APPEND","qbe_match":"LEADING"}

}

}

 

2_Create_Single_Custom_Attribute.PNG

 

[STEP 4] Unless you see any error, you should be able to see HTTP 201 status in the response section.  You can then open Class Manager to confirm the new attribute been added to the BMC_BaseElement class

 

[c] Create multiple custom attributes in a class using POST method

 

METHOD:  POST

 

REQUEST URL:    http://testserver:8008/api/cmdb/v1.0/attributes/{namespace}/{class}

 

[STEP 1] Create a new request in POSTMAN.  Select the method as 'POST'.   Type your REST API server URL in the following example format considering your are creating the following attributes  in BMC_ComputerSystem -  Custom_REQUIRED of entry_mode 'REQUIRED',  Custom_OPTIONAL of entry_mode 'OPTIONAL' and Custom_DISPLAY_ONLY of entry_mode 'DISPLAY_ONLY'

 

EXAMPLEhttp://testserver:8008/api/cmdb/v1.0/attributes/BMC.CORE/BMC_BaseComputerSystem

 

[STEP 2] Go to the Headers section and fill out the Authorization parameters like mentioned in the above picture 'Authorization token as Headers' (coped at the beginning of this blog)

 

[STEP 3] Switch to the BODY tab, select 'raw' as an option and change the format (available as a drop-down) from Text to JSON;  Copy the below JSON content inside the BODY tab, and then click SEND button.

 

Note:  When using the below JSON, remember to change the field ID for each field so that it is unique.  Also, keep track of 'entry_mode' field so you are using the appropriate one to get the desired outcome.

 

 

[

  {

    "name": "Custom_REQUIRED",

    "type": "REGULAR",

    "datatype": "CHAR",

    "characteristics": {

    "DESCRIPTION": "This is a Test Description",

        "DEPRECATED": false,

"AUDIT": "AUDIT",

"HIDDEN": true,

        "NAMESPACE": "BMC.CORE"

    },

    "limit": {

        "char_limit": {

            "pattern": "",

            "max_length": 255,

            "list_format": "STANDARD",

            "char_menu": "Test_Name",

"qbe_match": "ANYWHERE"

        }

    },

"field_id": 536871949,

    "entry_mode": "REQUIRED",

"default_value": "False",

    "class_id": "BMC_COMPUTERSYSTEM",

    "class_name_key": {

        "name": "BMC_ComputerSystem",

        "namespace": "BMC.CORE"

    }

  },

 

   {

    "name": "Custom_OPTIONAL",

    "type": "REGULAR",

    "datatype": "CHAR",

    "characteristics": {

        "DEPRECATED": false,

"AUDIT": "COPY",

        "NAMESPACE": "BMC.CORE"

    },

    "limit": {

        "char_limit": {

            "pattern": "ALPHA",

            "max_length": 255,

            "list_format": "",

"menu_style": "OVERWRITE",

            "char_menu": "",

"qbe_match": "EQUAL"

        }

    },

    "field_id": 536871944,

    "entry_mode": "OPTIONAL",

    "class_id": "BMC_COMPUTERSYSTEM",

    "class_name_key": {

        "name": "BMC_ComputerSystem",

        "namespace": "BMC.CORE"

    }

  },

  {

    "name": "Custom_DISPLAY_ONLY",

    "type": "REGULAR",

    "datatype": "CHAR",

    "characteristics": {

        "DEPRECATED": false,

        "NAMESPACE": "BMC.CORE"

    },

    "limit": {

        "char_limit": {

            "pattern": "DIGIT",

            "max_length": 255,

            "list_format": "",

            "char_menu": ""

        }

    },

    "field_id": 536871946,

    "entry_mode": "DISPLAY_ONLY",

    "class_id": "BMC_COMPUTERSYSTEM",

    "class_name_key": {

        "name": "BMC_ComputerSystem",

        "namespace": "BMC.CORE"

    }

  }

]

 

3_Create_multiple_Custom_Attributes.PNG

 

[STEP 4 ] Unless you see any error, you should be able to see HTTP 201 or HTTP 204 status in the response section.  You can then open Class Manager to confirm the new attributes have been added to the BMC_ComputerSystem class.  HTTP Response status '204' means server has processed the request, but it has not returned any content, it suggests that the attributes were created successfully.

 

[d] Modify a single attribute in a class using PATCH method

 

METHOD: PATCH

 

REQUEST URL:  http://testserver:8008/api/cmdb/v1.0/attributes/{namespace}/{class}/{attribute}

 

[STEP 1] Create a new request in POSTMAN.  Select the method as 'PATCH'.  Type your REST API server URL in the following example format considering you are modifying attribute  named 'test31' from BMC_BaseElement class

 

Examplehttp://testserver:8008/api/cmdb/v1.0/attributes/BMC.CORE/BMC_BaseElement/test31

 

[STEP 2] Go to the Headers section and fill out the Authorization parameters like mentioned in the above picture 'Authorization token as Headers' (coped at the beginning of this blog)

 

[STEP 3] Switch to the BODY tab, select 'raw' as an option and change the format (available as a drop-down) from Text to JSON;  Copy the below JSON content inside the BODY tab, and then click SEND button.  As an example, we have modified the field size of this attribute from '255' to '1024' - you can notice that in "max_length' parameter in the below JSON code.

 

{

"datatype":"CHAR",

"name":"test31",

"type":"REGULAR",

"class_id":"BMC_ASSETBASE",

"class_name_key":{"namespace":"BMC.CORE","name":"BMC_BaseElement"},

"characteristics":{"NAMESPACE":"BMC.CORE","DESCRIPTION":"Test 24","AUDIT":"NONE","HIDDEN":false,"CREATE_MODE":"PROTECTED"},

"entry_mode":"OPTIONAL",

"field_id":"234328",

"limit":{"char_limit":{"max_length":1024,"pattern":"","char_menu":"","menu_style":"APPEND","qbe_match":"LEADING"

}

}

}

 

4_Update_Single_Custom_Attribute.PNG

 

[STEP 4] Unless you see any error, you should be able to see HTTP 204 status in the response section.  You can then open Class Manager to confirm the attribute has been modified to the BMC_BaseElement class

 

[e] Delete a single attribute in a class using DELETE method

 

METHOD:  DELETE

 

REQUEST URL:   http://testserver:8008/api/cmdb/v1.0/attributes/{namespace}/{class}/{attribute}

 

[STEP 1] Create a new request in POSTMAN.  Select the method as 'DELETE'.   Type your REST API server URL in the following example format considering your are deleting the attribute 'test31' from BMC_BaseElement class

 

EXAMPLEhttp://testserver:8008/api/cmdb/v1.0/attributes/BMC.CORE/BMC_BaseElement/test31

 

[STEP 2] Go to the Headers section and fill out the Authorization parameters like mentioned in the picture 'Authorization token as Headers'  (copied at the beginning of this blog)

 

[STEP 3] Switch to the BODY tab, select 'raw' as an option and change the format (available as a drop-down) from Text to JSON;  Copy the below JSON content inside the BODY tab, and then click SEND button.

 

{

"datatype":"CHAR",

"name":"test31",

"type":"REGULAR",

"class_id":"BMC_ASSETBASE",

"class_name_key":{"namespace":"BMC.CORE","name":"BMC_BaseElement"},

"characteristics":{"NAMESPACE":"BMC.CORE","DESCRIPTION":"Test 24","AUDIT":"NONE","HIDDEN":false,"CREATE_MODE":"PROTECTED"},

"entry_mode":"OPTIONAL",

"field_id":"234328",

"limit":{"char_limit":{"max_length":255,"pattern":"","char_menu":"","menu_style":"APPEND","qbe_match":"LEADING"

}

}

}

 

[STEP 4] Unless you see any error, you may most likely notice HTTP 204 status in the response section.  You can then open Class Manager to confirm the  attribute has been deleted from BMC_ComputerSystem class.

 

NOTE: Updating and Deleting of multiple attributes will be covered in a future blog.  They are not covered in this blog on purpose as I faced some technical issues while testing those examples.  Hope you find this information useful.  Thank you for reading!