Managing Usage APIs in SAP Subscription Billing

Objective

After completing this lesson, you will be able to manage usage APIs to report, update, and retrieve usage data in SAP Subscription Billing.

Usage APIs to Report, Update, and Retrieve Usage Data in SAP Subscription Billing

Technical Resource IDs play a crucial role in identifying the correct subscription when processing usage data, ensuring that the data is accurately matched with the respective subscription during the billing process.

Upon creating a subscription, the rate element in our example for the BR469 product is designed to automatically generate technical Resource IDs to uniquely identify resources. Alternatively, you have the option to manually maintain their own Technical Resources.

In the following scenario, the system is configured to manage technical resource ID generation automatically. When it comes to uploading usage data to SAP Subscription Billing, each subscription item can be associated with one or multiple technical resource IDs. To begin generating usage data with an API, first acquire the technical resource ID for the subscription item that needs a usage record. You can open the Manage Subscriptions SAP Fiori app in the SAP Subscription Billing system and open the subscription item and check under Technical Resources. You may also send a GET Subscription Request to retrieve all information from the subscription.

Let’s see how to create a new request for a technical resource ID. Watch the following video to get started.

Now that you’ve had a chance to explore creating a technical resource ID with a REST CLIENT, let’s do it ourselves in the next exercise.

Get the Technical Resource ID for Sending Usage Data via API

Business Scenario

You are a developer implementing Subscription Billing for your company.

Your company offers a service with usage-based pricing. They need to implement a system to accurately track and bill customers based on their usage. Your task is to retrieve the technical resource ID for a specific customer's subscription, which will be used to send usage data via API.

Steps

  1. Repeat the exercise Get Customer ID and Create a subscription using the POST Subscription API, as the subscription was canceled.

    1. Perform the exercise again.

  2. Create a new Request in Bruno.

    Use the following data:

    FieldValue
    Name<of your choice>, for example: Get Subscription
    MethodGet
    URL

    https://eu10.revenue.cloud.sap/api/usage-record/v1/usage-records

    AuthBearer Token

    Technical resource ID: ______________________________________

    1. Create a new Request in Bruno, by choosing + in the tab.

    2. Give it a name of your choice, for example: Get Subscription.

    3. For the URL, change the method to POST and enter the URL: https://eu10.revenue.cloud.sap/api/subscription/v1/subscriptions.

    4. Choose Create.

    5. Replace the ID in the URL with the Bill ID from exercise 6.

    6. Open the Auth tab and select BearerToken.

    7. Enter the Bearer Token from the exercise Generate a Bearer Token to get Authorization for the APIs.

    8. Choose Send.

    9. Check that you receive a "200" Response and see a list with all subscriptions in the system. Once you find your subscription, you can search for the technical resource ID (Under the node "technicalResources"). Take note of the technical resource id.

    10. Once you find your subscription, you can search for the technical resource ID (Under the technicalResources node). Take note of the technical resource id.

Sending Usage Data to the SAP Subscription Billing System

Once you’ve obtained a technical resource ID, your next step is to send usage data to the SAP Subscription Billing system with your API. By providing the technical resource ID, the system associates the usage data with the appropriate subscription.

Within SAP Subscription Billing, the technical resource refers to the specific resources or services that are being consumed by the customer. These could be things like data storage, API calls, network bandwidth, or any other measurable resources or services that are being used within the subscription model. The technical resource is key to accurately tracking and billing customers based on their usage. In our scenario, the technical resource type is called USAGE_FEE and the ID will be an automatically generated technical resource ID. In real scenarios, the type could be, for example, API Calls and the ID could be the IP Address of the device.

In the next video, you will learn how to create a new POST request in Bruno to send usage data to the SAP Subscription Billing System, which you will then apply in the exercise.

Summary

Perform the following two exercises.

Now that you’ve had a chance to upload and consume usage data and create technical resources and their corresponding IDs, in the next unit you will manage Bill APIs to create, retrieve, update, and delete information in SAP Subscription Billing.

Send Usage Data to Your Subscription via API

Business Scenario

Now, your task is to send usage data (for example, the number of API Calls if you are customers pay per API Call) to the Subscription Billing system via API.

Steps

  1. Create a new Request in Bruno.

    Use the following data:

    FieldValue
    NameCreate Usage Data
    URL methodPost
    Used URLhttps://eu10.revenue.cloud.sap/api/usage-record/v1/usage-records
    AuthBearerToken

    1. Choose the + in the tab.

    2. Enter the name from the table.

    3. For the URL, change the method to POST and enter the URL: https://eu10.revenue.cloud.sap/api/usage-record/v1/usage-records.

    4. Choose Create.

  2. Add the Bearer Token.

    1. Open the Auth tab and select BearerToken.

    2. Enter the Bearer Token from the previous exercise.

  3. Enter the JSON, for example:

    Code Snippet
    12345678
    "startedAt": "2024-07-05T05:00:00Z", "endedAt": "2024-07-06T05:00:00Z", "category": "MEASURED", "metricId": "USAGE_FEE", "quantity": 5, "userTechnicalId": "your technical resource ID" }
    1. Open the Body tab and select JSON.

    2. Enter the given code.

    3. Choose the Send button.

      You should receive a 201 with the ID of the Usage Records.

Result

Now that you have uploaded usage data into the SAP Subscription Billing System, you need to verify whether the data is reflected in the system. You will send a GET request to verify the display of this usage data.

Send a GET Request to Retrieve Usage Data Information

Business Scenario

In this exercise, your task is to implement a system that retrieves usage data information for a specific customer's subscription using the Subscription Billing API. This information will be used to analyze customer's usage behavior.

Steps

  1. Create a new Request in Bruno.

    Use the following data:

    FieldValue
    NameGet Usage Data
    URL methodGet
    Used URLhttps://eu10.revenue.cloud.sap/api/usage-record/v1/usage-records
    AuthBearerToken

    1. Choose the + in the tab.

    2. Enter the name from the table.

    3. For the URL, change the method to Get and enter the URL: https://eu10.revenue.cloud.sap/api/usage-record/v1/usage-records.

    4. Choose Create.

  2. Add the Bearer Token.

    1. Open the Auth tab and select BearerToken.

    2. Enter the Bearer Token from the exercise Generate a Bearer Token to get Authorization for the APIs.

    3. Choose Send.

Log in to track your progress & complete quizzes