IT Operations Management (ITOM)
cancel

Code your infrastructure: Use APIs to script service consumption from CSA and HCM Suite

Code your infrastructure: Use APIs to script service consumption from CSA and HCM Suite

Ops_Guest Absent Member.

Guest post by Seetharam R, senior engineer and Sreeja EJ, functional architect

Here we go again, talking about an exciting new feature in Micro Focus Hybrid Cloud Management portfolio.APIs.png

 

It is not easy to under-state the value of APIs, so we will not. With the new simplified REST API for CSA subscriptions, you can literally script your service creation. Talk about “infrastructure as code”, this is a great place to start with the concepts and implementation. As the API is portable and accepts display names, use this to run across multiple CSA instances.  In this blog we will take you through the process of using the API, with postman client, show you how to use it with a sample design and service offering, giving you the code snippets to try this with.

 

You can use the new simplified subscriptions API to:

  • Submit a service request to create, modify or cancel a subscription
  • Issue user actions on a subscription
  • Resubmit a modify request that has failed
  • Submit a request based on an existing request

 

Couple of ground rules, to understand how to call and use the APIs:

  • Inputs are specified in the following hierarchy: Option Set -> Option -> Property.
  • For child Option Sets nested within an Option Property, it is not necessary to maintain the hierarchy. The Option Sets are a flat array regardless of whether the Option Set is at the top level or is nested.
  • You can reference the Option Sets, Options and Properties by their display names.
  • Instead of passing all option properties to the request body, you can pass only the options that are selected and the properties that have values different form the default value.
  • The API has thorough error handling capabilities with clear error codes. A detailed message about the problem is provided so that the caller can take corrective action.
  • The API thoroughly validates the request body input and sends errors with details.
  • APIs are versioned according to the semantic versioning scheme.
  • If the value for the dynamic property is not sent as a part of the POST body, the first value from the dynamic script will be set for the Property.

 

Pre-requisite

You need to know how CSA subscription creation works, and CSA service designer, option model. Take a look here if you need to refresh the basics.

By the way, one of the first users of this APIs is our very own HCM chatbot Maestro. More about Maestro in one of the next blog posts.

 

  1. Clone or Download “Simplified ServiceRequestAPIs” from Git hub.

https://github.com/seetharam043/Simplified-ServiceRequestAPIs

The folder contains a Sample Service offering to be imported on CSA and set of Service Request APIs that are readily available to import on POSTMAN API Client.

                POSTMAN API.png

Cloning can also be done through GitHub Desktop client as follows:

Go to https://github.com/seetharam043/Simplified-ServiceRequestAPIs

Click on the green “Clone or Download” button and then click “Open in Desktop” or “Download ZIP”.Simplified Service Request.png

 

2. Login to CSA and import sample Service offering (Demo Offering for Simplified API which is downloaded from GitHub) and Publish service offering to default Catalog.

3. Install Postman

Make sure you have POSTMAN installed to execute Service Request APIs. If you’ve never heard of Postman, it is a simple and free REST API client. It can be installed on Windows, OSX, and Linux (although this is currently a beta install). While there is a Chrome app, we have found the best experience is with the full client application.


 Postman can be downloaded at the following link: https://www.getpostman.com/apps.

4. From POSTMAN, choose files from local directory to Import all 3 json files as shown in below screenshot:

New Folder.png

 

5. After the import you will see list of Service Request APIs under POSTMAN Collections:CSA Service Request APIs.png

 

Request for X-Auth-Token

1. Select ‘Generate x-auth-token to authenticate consumer user’ API request from POSTMAN collections and update Basic auth using csa-idm integration account i.e. idmTransportUser.

And also make sure you update CSA hostname and Port as per your setup.

 

Generate x-auth-token.png

2. Update the Consumer User (the user login to MPP with Consumer Organization) details in the ‘Body’ payload and submit the request, the response contains a token ID(x-Auth-Token) which is valid for about 30 mins.Collections.png

 

Get Service Offering Details

Note: This API request is required to get request reference for service offering. You can ignore this API request if sample service offering used. ( service offering which is downloaded from github).

1. Select ‘Get Request Reference” API request to get request reference for service offering. Update x-auth-token generated in above step and submit the request, the response consists of name of service offering as Request reference.Get Request reference.png

 

Accept.png

 

Create Request

1. Select ‘Submit a service request to create a subscription’ API request from POSTMAN collections and update the Header with X-AUTH-TOKEN key value generated in above step.

 

Submit a service request.png

2. Update the current timestamp in startDate and submit the API request for service creationSubmit a service request collections.png

 

 

3. Similar way Requests like Modify, Cancel, Upgrade, Re-submit and Public action can also be executed using other Service Request APIs under Postman Collections.

Curl command to execute Service Requst APIs

1. Using Curl to generate x-Auth-token ID

curl -1 --insecure -v -H 'Accept:application/json' -H 'Content-Type:application/json' -u "idmTransportUser:idmTransportUser" -d '
{
"passwordCredentials" : {
"username" : "consumer",
"password" : "cloud"
},
"tenantName":"CONSUMER"
}' https://CSA_FQDN:PORT/idm-service/v2.0/tokens

2. Using Curl to get service offering name for Request Reference:

 Note: This API request is required to get request reference for service offering. You can ignore this API request if sample service offering used.

curl -l --insecure -v -H "Accept: application/json" -H "Content-Type: application/json" -H 'x-auth-token: token id generated in above step' -u admin:cloud -d '{}' https://CSA_FQDN:PORT/csa/api/mpp/mpp-offering/filter

3. Using Curl to create a subscription request:

curl -1 --insecure -v -H "X-Auth-Token: token id generated in above step" -H 'Accept:application/json' -H 'Content-Type:application/json' -u "admin:cloud" -d '
{
"requestReference":"Demo_Offering_for_Simplified_API_9c97699a-d775-4180-b53b-ee0988d02249",
"subscriptionName":"Simplified API",
"subscriptionDescription":"Demo API",
"startDate":"2018-02-22T09:45:19.000Z",
"action":"ORDER"
} ' https://CSA_FQDN:PORT/csa/api/urest/v1.0.0/serviceRequest

A comparing screenshots showing how option-set, options and properties in API payload differs from that of Marketplace portal UI:post API.png

 

 

Reference

https://docs.microfocus.com/CSA/4.80/Content/APIs/Subscription_API.htm

https://docs.microfocus.com/CSA/4.80/Content/Getting_Started/Concepts_Guide/Overview.htm

https://marketplace.microfocus.com/itom/content/hcm-chatops

https://github.com/seetharam043/Simplified-ServiceRequestAPIs

 

 

 

 

Comments
Micro Focus Frequent Contributor

Thanks for this post very useful for support.

while i was testing the samples everything worked as expected. I notice that not all samples were testable like the upgrade and the public acction.
Do you know samples i can use for this, the input sets taht we need to build are not 1 to 1 if you try to validate them against a manual request. The online docs does show good info but still not able to test them.