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: 
SatyaNigam
Product and Topic Expert
Product and Topic Expert
2,255

Introduction:


This blog post describes how SAP Cloud Platform API Management can be extended to leverage the capabilities of SAP Subscription Billing for metering API calls usage.

Use case:


Let's say you have a business service which is managed by SAP API Management and for a specific interval of time you want to generate bills/invoices of API consumption as per the standard markets and rate plans defined in SAP Subscription Billing system.

Solution:


From the Discover page in your API Management API Portal, copy the ‘Synchronization of API Metering Data’ API to generate a related API Proxy. The generated API proxy pushes the metering data into the SAP Subscription Billing system.

This API Proxy contains a set of predefined policies, which read metering data from API Management for the requested interval of time and pushes the data as an usage record** to SAP Subscription Billing system.
**Represents the time interval during which a quantity of usage data is collected from the metering system.

 

This extension capability is available as an API package 'SAP Cloud Platform API Management monetization using SAP Subscription Billing' in SAP API Business Hub, and connected API Management system could find this package in the Discover section of API Portal.

Prerequisites: -



  • Licensed and preconfigured API Management system for collecting API calls usage

    • Your business services are managed by API Proxy

    • API Proxy is published with a Product

    • Product is subscribed via Applications

    • API calls are made using the subscribed application key





  • Licensed and preconfigured SAP Subscription Billing system with relevant subscriptions

    • Defined Billing unit i.e. unit of measure for API calls usage









    • Defined Rate plan elements









    • Defined Product with relevant rate plans











    • Defined Customers for markets









    • Defined Subscription 






Design: -




 

Follow the steps below to enable synchronization.

Steps: -


For API Proxy Creation



  • Launch the SAP Cloud Platform API Management - API Portal and log on to the application.




 

  • Click on hamburger icon and navigate to the Discover page by selecting the Discover tab




 

  • Search for the API package with title - 'SAP Cloud Platform API Management monetization using SAP Subscription Billing'




 

  • Click on the package title to navigate to its details and click on Artifacts tab




 

  • For the API with title - Synchronization of API Metering data, click Actions menu and select Copy from the drop-down menu




 

  • Copy API wizard will open with pre-populated fields, retain the default values(where Name, Title and API Base Path field could be changed) and select OK




 

  • Navigate to Develop tab where the above created API Proxy would be listed under APIs view.




 

  • For the created API Proxy, click Action menu and select Deploy from the drop-down menu items to deploy the API Proxy




 

  • API Proxy shall be in Deployed status after successful deployment




 

For Key Value Map(KVM) Creation



  • Navigate to Configure tab and select Key Value Maps tab, where following KVMs need to be created with exactly the same keys mentioned in below table(replace placeholders <> with actual values):-




 



    • For storing SAP API Management and SAP Subscription Billing system details:









      • Click the Create button which will displays the Create Key Value Map view












      • Provide the Name as APIM_SB_ACCOUNT_DETAILS

      • Select checkbox Encrypt Key Value Map

      • Enter Key = APIM_APIPORTAL_DETAILS

      • Enter Value = {"hostUrl":"<apim_host_url_without_scheme**>","user":"<apim_user>","password":"<apim_pwd>"}

      • Click Add button to add another entry

      • Enter Key = SB_DETAILS

      • Enter Value = {"tokenUrlHost": "<token_url_host_without_scheme**>","clientId": "<client_id>","secret": "<client_secret>","hostUrl": "<sb_host_url_without_scheme**>"}

      • Select Save button to publish the newly created encrypted KVM


























KVM Name Encrypted KVM - Key KVM - Value
APIM_SB_ACCOUNT_DETAILS Yes APIM_APIPORTAL_DETAILS {"hostUrl":"<apim_host_url_without_scheme**>","user":"<apim_user>","password":"<apim_pwd>"}
SB_DETAILS {"tokenUrlHost": "<token_url_host_without_scheme**>","clientId": "<client_id>","secret": "<client_secret>","hostUrl": "<sb_host_url_without_scheme**>"}

** without 'https://' in the url

 



    • For storing SAP API Management Application Key and SAP Subscription Billing Subscription ID & Metrics ID mapping details









      • Click the Create button to create non-encrypted KVM












      • Provide the Name as APIM_SB_MAPPING_KVM

      • Keep checkbox Encrypt Key Value Map un-selected

      • Enter Key = APPID-SUBID_METID

      • Enter Value = {"<apim_appid_1>":{"sid":"<sb_sid_1>","mid":"<sb_mid_1>"},"<apim_appid_2>":{"sid":"<sb_sid_2>","mid":"<sb_mid_2>"},….}

      • Select Save button to publish the newly created non-encrypted KVM






















KVM Name Encrypted KVM - Key KVM - Value
APIM_SB_MAPPING_KVM No APPID-SUBID_METID {"<apim_appid_1>":{"sid":"<sb_sid_1>","mid":"<sb_mid_1>"},"<apim_appid_2>":{"sid":"<sb_sid_2>","mid":"<sb_mid_2>"},….}

 

  • By following the above-mentioned steps both the required KVMs would have been created.



Note:-


apim_appid* = SAP API Management - Application ID against which the metering data needs to be read

sb_sid* = SAP Subscription Billing - User Technical ID (The identifier of the customer)

sb_mid* = SAP Subscription Billing - Metric ID (The identifier of the metric of usage)

 

Once the above mentioned steps are completed, you are good to invoke the API Proxy URL to initiate the usage record sync for the given period. It could possibly be triggered by CRON job, Jenkins or any application of your choice.

Here is the screenshot of postman rest client doing the HTTP GET call by providing the Start Date and End Date with reference to Coordinated Universal Time (UTC) in the format YYYY-MM-DDTHH:MMZ



 

You will get either a HTTP 200 Success or HTTP 400/500 Failure response based on the sync processing result accordingly.

Boundary Conditions: -



  • Limited processing of mapping records due to API Portal policy timeout restriction (max. 100 records)

  • Minimal date checks are enabled via API Management policy, like End date must be later than the start date

  • Due diligence required to ensure no overwriting or duplicate records for usage data


Future Scope: -



  • Creation of Rate plans, Products and Subscription in SAP Subscription Billing via API Portal policy by directly reading details from connected API Management system.

  • Auto creation of referenced KVMs in policies during copy of API.


Conclusion:-


This is how SAP Subscription Billing capabilities can be extended to SAP API Management for generating better customer value. This extensibility provides us a unified solution for all our Pricing and Billing needs related to API monetization.
3 Comments
svenhuberti
Product and Topic Expert
Product and Topic Expert
0 Kudos
Thanks for this blog! Quite usefull!

Just one remark: I was getting a lot of errors in the beginning and I pinpointed the issue to the KVM values which were not set right (I did "copy/paste"): the double quotes became question marks. But the thing is: you can't see that in the encrypted values! So the JSON Parser of APIM could not find the values of the user and so on...

My solution was to use a code editor to replace the double-quotes from this blog with UTF-8 double-quotes.
SatyaNigam
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hello svenhuberti,

Pleased to receive your kind feedback ?

Just curious to know if this double quotes issue could be fixed in this blog itself.

Thanks – Satya
svenhuberti
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi Satya,

I don't know if you can fix the issue in the blog itself but it's worth mentioning.

Also, another simple solution is to use the API Management APIs for KVMs, not the UI.

BR,

Sven