Skip to main content


Invoke Business Rule Using EPBCS REST API in Groovy – Part 2

This is a continuation of my special blog series. You can read Part 1 here.

Groovy script is basically split into four sections. We previously covered a short description of the sections, so we are getting directly into the script here.

Code Section 1

This section imports the java libraries which help in formatting the payload and reading the JSON Response from server.

import org.json.JSONObject
import groovy.json.JsonSlurper

JSONObject class is used to use the put method which pushes the parameters to payload.
JsonSlurper is a class that helps to convert JSON data into groovy data.

Code Section 2

Setting up user Credentials and other information related to REST API.As per oracle below are the expected format

1. API Version – 3
2. username – domain.username:password
3. authentication – HTTP Requests require Basic Authentication “Basic ” + javax.xml.bind.DatatypeConverter.printBase64Binary

Code Section 3

This section defines the list of common functions which are already developed by Oracle. Readers should have basic understanding of Java language to understand the groovy functions. Below are the list of common functions which are provided by Oracle and used in our example.

 fetchResponse – method used to read the response and convert into lines.

Oracle - Guide to Oracle Cloud: 5 Steps to Ensure a Successful Move to the Cloud
Guide to Oracle Cloud: 5 Steps to Ensure a Successful Move to the Cloud

Explore key considerations, integrating the cloud with legacy applications and challenges of current cloud implementations.

Get the Guide

 fetchJobStatusFromResponse – method used to read the job status of business rule submitted.

Below are the custom methods used specifically to call the business rule.

1. Setup the connection using the EPBCS URL.

2. Authenticate user with credentials.
3. Set request properties and Request Type as POST.
4. Invoke the url and read the status code.

5. Status code is expected to be 200 for GET and 201 for POST. If there are any other status codes then please refer to Oracle Error Codes.

1. Format the URL string to be passed.

2. Split the parameters if there are more than 1 parameter.

Program explained in this blog has only 1 parameter but I have added the code to make sure the method supports No param or more than 1 parameters.
3. Call the executeRequest explained above.

Code Section 4

This is the last main section which actually calls the business rule with parameters. Below screenshot very clearly shows that Push_Data rule  is invoked with a parameter Entity.


Code can be reused with few tweaks in Section 2 and Section 4. Validate and run  the program in the groovy console to invoke the business rule. Additional logic for deriving the parameters can be added in Section 4. Below screenshot shows the email sent by EPBCS on successful completion of business rule.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Nesajosbenny Britto

More from this Author

Follow Us