## 6.1.4.2.1 Configuration for Using the Resource Consumption APIs in the SAP Business Accelerator Hub
The Resource Consumption APIs of the SAP Usage Data Management service for SAP BTP are protected with OAuth 2.0 Client Credentials grant type and in some cases, also the Password grant type.
##  Note
OAuth 2.0 Password grant type is only mandatory for the subaccountUsage API.
## Prerequisites
- To use the Resource Consumption APIs of the SAP Usage Data Management service
- You must have service access to the relevant uas service plan. For information about available service plans, see SAP Usage Data Management Service - Service Plans [page 2492].
- When using Password grant type the user must be assigned one of the following role collections:
| API                                                          | Role Collection Required                               |
|--------------------------------------------------------------|--------------------------------------------------------|
| monthlyUsage , /monthlySubaccountsCost , and subaccountUsage | Global Account Administrator and Global Account Viewer |
For more information, see Role Collections and Roles in Global Accounts, Directories, and Subaccounts [page 125].
##  Note
To create a service instance in other environments using the Service Manager Control (SMCTL) CLI, SAP Service Manager APIs, or the SAP BTP cockpit, see Consuming Services in Other Environments Using the SAP Service Manager Instances.
## Procedure
1. Create a service instance for the service plans that correspond to the APIs that you want to use. When you create the service instance, specify the following parameters:
- PLAN: The name of the service plan that you want to use. See SAP Usage Data Management Service Service Plans [page 2492].
- SERVICE\_INSTANCE: Name of the service instance.
There are several options available to create instances depending on the environment you use.
- To create a service instance in other environments using the Service Manager Control (SMCTL) CLI or SAP Service Manager APIs, see Consuming Services in Other Environments Using the SAP Service Manager Instances.
- To create a service instance in the Cloud Foundry environment using the SAP BTP cockpit or the cf CLI, see Creating Service Instances [page 254].
- To create a service instance in Kyma using the Kyma dashboard, see Using SAP BTP Services in the Kyma Environment [page 2019].
##  Recommendation
If you are not working in Cloud Foundry, Kyma, or Kubernetes, use the SAP Service Manager to create and manage service instances. These instances are platform-agnostic and can be deployed and integrated with any other environment of your choice.
2. Get the OAuth 2.0 client information and uas service endpoints by creating a service key or binding. There are several options available to create service keys or bindings depending on the environment you use.
- To create bindings in other environments, see Consuming Services in Other Environments Using the SAP Service Manager Instances.
- To create a service key in the Cloud Foundry environment using the SAP BTP cockpit or the cf CLI, see Creating Service Keys [page 259].
- To create credentials for calling the service and retrieving information in the Kyma environment, see Using SAP BTP Services in the Kyma Environment [page 2019].
3. Use uaa\_url , clientid , and clientsecret to request an access token using the following commands:
```
 Sample Code For Windows OS (Password grant type): curl -L -X POST "<uaa_url>/oauth/token" ^ -H "Content-Type: application/x-www-form-urlencoded" ^ -u "<clientid>:<clientsecret>" ^ -d "grant_type=password" ^ -d "username=<user email>" ^ -d "password=<password>"
```
```
 Sample Code For Windows OS (Client Credentials grant type): curl -L -X POST "<uaa_url>/oauth/token" ^ -H "Content-Type: application/x-www-form-urlencoded" ^ -u "<clientid>:<clientsecret>" ^ -d "grant_type=client_credentials" ^
```
```
 Sample Code For Mac OS (Password grant type): curl -L -X POST '<uaa_url>/oauth/token' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -u '<clientid>:<clientsecret>' \ -d 'grant_type=password' \ -d 'username=<user email>' \ -d 'password=<password>'
```
```
 Sample Code For Mac OS (Client Credentials grant type): curl -L -X POST '<uaa_url>/oauth/token' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -u '<clientid>:<clientsecret>' \ -d 'grant_type=client_credentials' \
```
 Note The access token that you receive also contains the scopes that are granted for this access token. Therefore, only APIs that require one of these scopes can be used with this access token. { "access\_token": "&lt;access\_token&gt;", "token\_type": "bearer", "expires\_in": 43199, "scope": "&lt;xsappname&gt;.UAS.reporting.GA\_Admin" }
4. Using the &lt;access\_token&gt; that you received in the previous step you can call the Resource Consumption APIs using bearer authentication or you can try them directly in the SAP Business Accelerator Hub using the following steps:
1. Got to Resource Consumption APIs in the SAP Business Accelerator Hub.
2. Choose Select Environment and select the Add New Environment option
3. In the Authentication Type field, select OAuth 2.0 Application Flow .
4. Provide the parameters that you have retrieved in the following fields: clientid , clientsecret , and identityzone .
5. Save your changes.
5. Choose the API that you want to call, provide the relevant parameters, and choose Run .
To learn more about the SAP Business Accelerator Hub, see What Is the SAP API Business Hub?