Skip to Content

Test the Business Rules API from SAP API Business Hub

test
0 %
Test the Business Rules API from SAP API Business Hub
Details

Test the Business Rules API from SAP API Business Hub

September 29, 2021
Created by
September 19, 2019
Use SAP API Business Hub to test and run the business rules API to see how business rules can be consumed from a custom application.

You will learn

  • How to use Business Rules APIs
  • How to test Business Rules project
QR code

Prerequisites

After a rule service is deployed to a custom application, the rule service should be invoked to implement the decision logic. In this tutorial, we will simulate the rule service invocation by invoking the rule service from SAP API Business Hub.

Business Rules REST APIs are available on SAP API Business Hub which lets you execute rules from custom applications and external REST clients. Since these APIs are based on OAuth 2.0 authorization, you need the client credentials to access them. You get the client credentials from the service key of the business rules service instance.

Step 1: Log on to SAP API Business Hub
  1. Log on to SAP API Business Hub

    API Hub Homepage
  2. In the search bar, search for Business rules. From the search results, select the API package for SAP Business Rules Service.

    Search bar
  3. Choose the Rule Execution API for Cloud Foundry tile of Version v2.

    Rule Execution API tile
  4. Choose Try out to execute the APIs.

    Try out
Log on to answer question
Step 2: Determine the service key parameters to configure environment

To try out the APIs, you need to configure your trial environment on SAP API Business Hub. The communication between a REST client (SAP API Business Hub in this case) and the service is achieved via a service instance. You can use the service keys to generate credentials to communicate with a service instance. Since Business Rules APIs are based on OAuth 2.0 authentication, you need to configure the environment using the service key parameters or the client credentials.

  1. Log on to SAP BTP Cockpit.

  2. Choose Enter your trial account.

    Log on screen
  3. Choose the trial subaccount where you have the Workflow Management service subscription.

    subaccount
  4. From the navigation menu, choose Instances and Subscriptions. Under Instances, choose the Credentials to open the service key of the wm_business-rules service instance.

    service instances
  5. From the service key, note the following parameters required for configuring the environment:

    • clientid
    • clientsecret
    • url
    service key parameters
Log on to answer question
Step 3: Configure the environment

Configure the environment using the service key parameters or the client credentials determined in step 2.

  1. Go to SAP API Business Hub and then choose Add New Environment.

    Configure environment
  2. In the Configure New Environment window, provide the following details:

    Under Basic Information section:

    Field Name Value
    Display Name Trial
    Runtimeurl bpmruleruntime.cfapps.eu10.hana.ondemand.com

    Configure environment

    Under Authentication section:

    Field Name Value
    Client ID clientid
    Client Secret clientsecret
    Token URL url

    Enter the token URL without https://. For example, if the token URL in the service key is https://<trial ID>.authentication.eu10.hana.ondemand.com, then enter <trial ID>.authentication.eu10.hana.ondemand.com.

    Then, choose Configure.

    Configure environment
Log on to answer question
Step 4: Invoke the rule services and observe the results in the API response
  1. Fetch the ID of the DetermineEquipmentRuleservice rule service from Manage Rule Projects application. This is a required parameter in the body JSON payload of the API.

    In the Rule services tab, choose Settings icon.

    Configure environment

    Select ID and choose OK.

    Configure environment

    Copy the ID of the DetermineEquipmentRuleservice rule service.

    Configure environment
  2. In SAP API Business Hub, select Invoke a Rule Service API and then choose /v2/workingset-rule-services. Paste the rule service ID in place of <rule-service-ID> in the following JSON payload and copy it to the Body of the API:

        {
      "RuleServiceId": "<rule-service-ID>",
      "Vocabulary": [
        {
          "Employee": {
            "IsFullTimeEmployee": true,
            "countryofCompany": "USA",
            "jobTitle": "Engineer II",
             "company": "ACE_USA"
           }
        }
      ]
    }
    

    Then choose Run.

    Configure environment
  3. Observe the API response in the response body of the API. You can view the equipment assigned to the employee.

    Configure environment
  4. Similarly, fetch the ID of EquipmentApprovalRuleservice from Manage Rule Projects application like in Step 3.1.

  5. Paste the rule service ID in place of <rule-service-ID> in the following JSON payload and copy it to the Body of the same API:

        {
      "RuleServiceId": "<rule-service-ID>",
      "Vocabulary": [
        {
          "Equipment": {
            "TotalAmount": 780
           }
        }
      ]
    }
    
  6. Observe the API response in the response body of the API.Configure environment

    You also try changing the rule logic or the JSON payload values to see different results.

How do you determine the OAuth 2.0 parameters required for configuring the environment on SAP API Business Hub?
×

Next Steps

Back to top