How to get Cost Optimization’s Underutilized API

This article guides you how to get the underutilized report from Cloud Expense's Underutilized API. Follow the below steps:

Step 1: Get access-token by using usernamepassword

Mandatory parameters include:

  • username
  • password
  • keycloak_client_id
  • keycloak_realm

Get access-token from the service provider. Execute the command using the above parameter value:

curl --location 'https://sso.dxcloudsuite.io/auth/realms/<keycloak_realm>/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=<keycloak_client_id>' \
--data-urlencode 'username=<username>' \
--data-urlencode 'password=<password>'

Once the request is successful, the response returns as below:

{
"access_token": ,
"expires_in": 3600,
"refresh_expires_in": 10800,
"refresh_token": ,
"token_type": "Bearer",
"not-before-policy": 0,
"session_state": "a0fe3038-c490-49d5-8f16-7c2ed3ea8bd5",
"scope": "email profile"
}

Using refresh-token to get a new access-token

An access-token has an expiration time. When the access-token is expired, you can use the refresh-token to get a new access-token.
Using the refresh-token, you don't need to use the username and password of user.

Send a request to keycloak to get a new access-token. Execute curl command with the corresponding value:

curl --location 'https://akaclaud.aka-sso.io/auth/realms/akaclaud-aiops-realm/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=refresh_token' \
--data-urlencode 'client_id=' \
--data-urlencode 'refresh_token='

Once the request is successful, the response is as below:

{
"access_token": ,
"expires_in": 3600,
"refresh_expires_in": 10800,
"refresh_token": ,
"token_type": "Bearer",
"not-before-policy": 0,
"session_state": "a0fe3038-c490-49d5-8f16-7c2ed3ea8bd5",
"scope": "email profile"
}

Step 3: Using RestApi to get the report file

Inputting data in the API testing tool to get the report file. The data includes:

  1. Method: GET
  2. RESTful API: Contact the CloudSuite One admin
  3. Header:
    Key: Authorization - Value: Bearer + {access-token}

Once the request is successful, you will be able to get the expected report.

Note: Only Company owner's user can get data, other users can't do it.