Extending SAP Asset Performance Management: Consume Standard API
The blog post is part of the series Side-by-Side Extension of SAP Asset Performance Management.
In this blog, we shall walkthrough the steps to be followed by end users for consuming APIs published by SAP Asset Performance Management (hereinafter referred to as “APM“ for brevity).
APM provides different types of APIs (like OData, GraphQL and REST) catering to business objects served by different APM modules and services. The following diagram shows the indicative topology of APM components and services involved in API flow.
SAP Asset Performance Management application entitlement is assigned to a BTP sub-account and already subscribed to it.
1. Explore APM APIs
APM APIs are published in SAP Business Accelerator Hub (https://api.sap.com). To explore different APIs that APM has to offer, follow the steps given below.
1.1 Go to https://api.sap.com in web browser of your preference
1.2 Search for keyword “APM” in search box
1.3 APM APIs are grouped into 3 API packages
Manage Asset Data (Foundation)
Provides APIs to maintain asset data, such as equipment and functional location data. It also provides APIs to manage some of the transaction and configuration data objects, like Failure Data.
Provides APIs to manage asset health related data objects like Indicators, Timeseries, Notifications etc.
Provides APIs to manage maintenance strategies like Risk and Criticality assessment, Strategy Assessment for Classes, RCM, Recommendations etc.
Select the APM API package you would like to explore
1.4 Select the required API tile to view details
1.5 Click on ‘API Reference’ tab to view list of APIs
1.6 Click on ‘Configuration Details’ option under Overview tab to see list of production host URLs.
URLs contain a placeholder for ‘host’, which should be replaced with application host value obtained from APM Service Key, which is explained in section 3.
1.7 APM provides different API types like OData, REST and GraphQL. Asset Strategy package mainly contains GraphQL APIs
1.8 To explore GraphQL Queries, Mutations and Types for a particular API, click on ‘API Reference’ tab
1.9 To download GraphQL schema file, click on Download option as shown in screenshot below
2. Obtain APM Service Key and API Key
In order to call APM APIs, we need to first obtain following details which are pre-requisites for accessing APM APIs.
- Client Credentials (Client ID and Client Secret)
Used to generate JWT token. Generated Token to be sent as Authorization request header while calling APIs.
- API Key
To be sent as request header (X-API-Key) while calling APIs.
2.1 Fetch Client Credentials from APM Service Key
To generate APM Service Key, follow the steps mentioned in this link .
Generated APM Service Key contains information such as
- Endpoints – list of application URLs to be used for accessing APM APIs
- Client Id, Client Secret and Auth URL – used to generate JWT Token
2.2 Obtain API Key
Every API request must include ‘X-API-Key’ request header to ensure that the client application can authenticate itself while accessing APM APIs.
You can obtain the API Key by creating a ticket on the component APM-OPS. Provide the following details in the ticket:
- Sub-Account ID
- Sub-Account API end point/APM FLP: To identify landscapes
- Email ID: to send API key
2.3 Generate JWT Token
3. Construct API Endpoint (URL)
Now let us construct an API endpoint using information obtained from Service key and URLs provided in SAP Business Accelerator Hub.
For demonstration purpose, we will construct an API endpoint for Technical Object Service. However, you can apply the same method to construct URLs for other APM APIs as well.
3.1 Fetch application endpoint from Service Key (refer 2.1)
3.2 Fetch production URL from SAP Business Accelerator Hub (refer 1.6)
3.3 Substitute “host” part in the production URL with host subdomain part provided in endpoint, as shown below
Resultant base URL now looks like this :
3.4 Append API endpoint to base URL
API endpoint can be obtained from API reference as shown below
3.5 Final API endpoint URL now should look like this
4. Calling an API
In Rest client, use the API URL constructed in step 3.5. Also set the following request headers.
value should be ‘Bearer ‘ + <JWT Token generated in step 2.3>
value should be API Key obtained in step 2.2
Clicking on “Send” button should invoke the API and return the response as shown below.
APM provides different types of APIs based on nature of the business objects it publishes. OData, GraphQL and REST APIs are tailored to make it easier for application developers to work with APM objects and data.
To learn about APM GraphQL APIs and how to use them, refer to blog post Extending SAP Asset Performance Management: Working with APM GraphQL APIs
Stay tuned for further blog posts in the series. Share your feedback or thoughts in the comment section of this blog post.