Generally, 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.
SAP Cloud Platform 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
-
Log on to SAP API Business Hub
-
In the search bar, search for Business rule. From the search results, select the API package for SAP Cloud Platform Business Rules.
-
Choose the Rule Execution API for Cloud Foundry tile of Version v2.
Step 2: Determine the service key parameters
Service key parameters are required to configure the environment in SAP API Business Hub.
-
Log on to SAP Cloud Platform Cockpit.
-
Choose Enter your trial account.
-
Choose your trial subaccount.
Choose your space.
In the following screenshot, the name of the space is dev
. Space name can also be a custom name that you have provided.
-
From the navigation menu, choose Service Instances.
-
From the list of available service instances, choose wm_business-rules
.
-
From the navigation menu, choose Service Keys and then choose Create Service Key.
-
In the Create Service Key window, provide the name of the service key as business-rules or any name of your choice, and then choose Save.
Service key of wm_business-rules
service instance will be created.
-
From the service key, note the following parameters required for configuring the environment:
clientid
clientsecret
url
Step 3: Configure the environment
You need to configure the environment to link it to the business rules project which you have created in Manage Rule Projects application. Since Business Rules APIs are based on OAuth 2.0 authentication, you need to provide the client credentials determined in step 2.
-
Choose Configure Environments.
-
In the Configure Environments window, provide the following details:
Field Name |
Value |
Display Name for Environments |
EU10 |
runtimeurl |
bpmruleruntime.cfapps.eu10.hana.ondemand.com |
Client Id |
clientid |
Secret |
clientsecret |
tokenurl |
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 Save.
Step 4: Invoke a rule service
-
Select Invoke a Rule Service API and then choose /v2/workingset-rule-services
. Then choose Try out to execute the API.
-
Fetch the rule service ID from Manage Rule Projects application. This is required for the API JSON payload.
In the Rule services tab, choose Settings icon.
Select ID and choose OK.
Copy the ID from the rule service.
-
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": "2000"
}
}
]
}
Then choose Execute.
Step 5: Observe the API response
You can view the equipment assigned to the employee in the response body of the API.