Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Neuert
Product and Topic Expert
Product and Topic Expert


In the first part of the introduction of Cloud Management Tools I showed the Command Line Interface (CLI) of SAP Cloud Platform. In this blog I will show you the APIs (application programming interfaces) for SAP Cloud Platform.

SAP Cloud Platform – Core Service APIs (Beta)


The new core service APIs allow you to manage, build, and extend the core capabilities of SAP Cloud Platform. Each core service focuses on a different aspect of the platform, from the management of accounts and product entitlements, through to the registration and provisioning of subscriptions for multitenant applications and services.

Use this URL to access the interface where you can explore the available APIs and try them out:

api.sap.com

You’ll find seven API packages that are offered by three main core services: Cloud Management, User Data Management, and Service Management. There is also an additional Events Service APIs. For more information see help.sap.com.


Core Services APIs



Cloud Management (Beta)


This service offers the Accounts, Entitlements, Provisioning, SaaS Manager, and Events packages. To use them, use the sapcp CLI

  1. sapcp assign accounts/entitlement --to-subaccount subaccount1 --for-service cis --plan central --distribute 'true' --enable 'true' --auto-assign 'true' (where subaccount1 is your subaccount ID)

  2. cf create-service cis central cisinstance (where cisinstance is your instance name)


or go to the cockpit and entitle the “Cloud Management (Beta)” service to your account and enable it (create a service instance). To get full access to these API packages, use the service plan “central”.


Cloud Management - Entitlements


The next step is to create a service instance:


Service Instance


And then you must create a service key:


Service Key


First, we need an access token to use the APIs. You can get an access token via CLI or via API. Please keep a note of your <url><clientid>, and <clientsecret>.

Create an access token with command line using your <url>, <clientid>, and <clientsecret>  (get more information here😞

Example for Mac OS:
curl -L -X POST '<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>’

Or, you can create an access token via API (for example, using Postman):


Use POST and enter <url>/oauth/token’, Content-Type:"application/x-www-form-urlencoded" and Authorization “no auth”


In the body, enter grant-type: password, and your SAP Cloud Platform login e-mail and password for username and password, respectively.

If all goes well, you'll get your access_token. You must add this access token to Swagger to be authorized. Let me show you how…

Open Swagger and click on Accounts:


Then, click on



and add “Bearer <access_token>” into the Value field (remember to leave a space between "Bearer" and the actual token):



Now you can try out the service!


 

You should get a response that looks something like this:
  "guid": "…",
"displayName": "…",
"createdDate": 1597396380178,
"modifiedDate": 1597396380178,
"entityState": "OK",
"stateMessage": "Global account created.",
"subdomain": "atrial-ga",
"contractStatus": "ACTIVE",
"commercialModel": "Subscription",
"consumptionBased": false,
"licenseType": "TRIAL",
"geoAccess": "STANDARD",
"renewalDate": 1597396380060

Usage Data Management


The Usage Data Management currently offers the Resource Consumption API, which as its name suggests allows you generate reports based on the resource and cost consumption. Very useful. To use it, you must first entitle the Usage Data Management service and then enable it.

To get full access to this API package, use the service plan “uas”.


Service Instance UDM


And then create a service key similar to before:


Service Key


Again, to use the APIs you need to use <url> , <clientid>, and <clientsecret> to create an access token via CLI or API.

To create an access token with command line, see this example for Mac OS:
curl '<uaa_url>/oauth/token' -X POST \ 
-H 'Accept: application/json’ \
-d 'grant_type=client_credentials&client_id=<clientid>&client_secret=<clientsecret> '

Or you can create an access token via API (using e.g. Postman):


Postman - UDM Header


Use POST and enter <url>/oauth/token, Accept: application/json

And enter grant_type: client_credentials, with your client_id and client_secret in these fields, respectively:


Postman - UDM body


Open Swagger and click on


Resource Consumption


Click on

 


and add “Bearer <access_token>” into the Value field:


 

Now you can try out the service. Remember, if your account is new, you might not see much usage data.

Enter fromDate and toDate to specify the date range:


As a result, you should see this as example:
{
"content": [
{
"globalAccountId": "…",
"globalAccountName": "atrial",
"subaccountId": "…",
"subaccountName": "Mars",
"directoryId": "…",
"directoryName": "DIRECTORY",
"reportYearMonth": 202008,
"serviceId": "hana-cloud",
"serviceName": "SAP HANA Cloud",
"plan": "hana",
"planName": null,
"environmentInstanceId": "…",
"environmentInstanceName": "myname",
"spaceId": "…",
"spaceName": "dev",
"instanceId": "…",
"measureId": "capacity_units",
"metricName": "Capacity Units",
"unitSingular": "capacity unit",
"unitPlural": "capacity units",
"identityZone": "",
"dataCenter": "cf-eu10",
"dataCenterName": "cf-eu10",
"usage": 41.48
},
{

With these two core services, you can now easily create and manage your account environment, activate services, and get usage reports.
5 Comments