In this blog, we’ll discuss how to Leverage OCI Functions to invoke OIC Integrations.

Following is the sample architecture, how to use OCI Functions to call Oracle Integrations.

Simple Architecture on calling OIC Integrations from OCI Functions

Pre-Requisites

  • Access to OCI Console.
  • Access to OIC Instance and availability of Integrations to cover the below scenarios.
  • Access to create Function Applications & Functions within a compartment.
  • Availability of a VCN & Subnet with a Function Application created.
  • Availability of AuthToken for your user.

Assuming the above pre-requisites are met. We will discuss how to call OIC Integrations from OCI Functions covering the below scenarios.

Scenarios

a. Calling OIC Integration which doesn’t need any input Parameters → Calling an OIC EchoWorld Integration from OCI Functions.
b. Calling OIC Integration with a single Input & Output Parameter → Calling an OIC Hello World Integration from OCI Functions.
c. Calling OIC Integration with a single Input & Multiple Output parameters → Calling an OIC FetchEmpData Integration from OCI Functions.
d. Calling OIC Integration with multiple Input & Multiple Output parameters → Calling an OIC FetchEmpDeptData Integration from OCI Functions.

NOTE: To explain all these scenarios I am choosing Python as my language to build Functions. I will be building and invoking functions from OCI Cloud Shell in this blog. You can set it up on your local as well which ain’t scope of this blog.

Setting up Environment for OCI Function

How to create to the Fn environment and create a boiler plate function is given in detail in OCI Console.

There are 3 parts to any function: (I) Creating (II) Deploying & (III) Invoking.

Scenario (a) –> Calling EchoWorld Integration (without parameters)

Generating Boiler Plate code

In this, we’ll first generate a boilerplate code for function using the command.

fn init --runtime python <FunctionName>

I will create a function for OICEchoWorld as below:

fn init --runtime python OICEchoWorld

These create a function code with a directory OICEchoWorld in a chosen repo with 3 files (func.yaml, func.py & requirements.txt).

In the above snippet, you are seeing an extra file InvokeEchoWorld.py, which we have created to invoke OIC Integration.

You might ask why can’t we write the entire code in a single .py file rather than in separate files? We can very well do that, but I want to keep func.py as a standard file which can be replicated across different other functions and keep another function specific to calling OIC Integration.

func.py

  1. Boilerplate creates a handler function which will be where the incoming hit to your function land.
  2. Declaring logging i.e., level of logging and format of log i.e., with time followed by logging level (INFO) and the message to be printed in your log.
  3. Declaring response variable to be returned.
  4. Storing data from input configuration variables in temp variables.
  5. Imported the integration related .py file, calling function/method inside that file along with parameters and storing output of that call in “resp” variable.

InvokeEchoWorld.py

  1. storing username & password in a temp variable, to be passed to OIC call.
  2. sending GET method request to the Integration endpoint via oicbaseurl along with credentials.
  3. setting values to be returned in case of success. Sending “Message” field value from Integration output via ‘output’ field.

requirements.txt

Need to add few more records on top of the boiler plate generate here w.r.t OCI version and requests package which needs to be imported for calling OIC Integration.

func.yaml

This file basically gives your information as to name, version, runtime, memory etc., of your function.

Deploying Function

To deploy a function you need to use the below command:

fn -v deploy --app <FunctionApplicatioName>

In our case, we will have to run as below

Configuring Function Variables

Post deploying the function, in my case I am setting the OIC Integration endpoint and credentials to make a call.

Invoke Function

To invoke a function you need to know the name of the function, which can be obtained via the below command:

fn list Functions <FunctionApplicationName>

Now that we have the Function Name, let us invoke the function as below:

fn -v invoke <FunctionApplicationName> <FunctionName>

Trigger In OIC

Scenario (b) –> Calling HelloWorld Integration (with Single Input & Output parameters)

Here I will be covering only the Integration specific .py file and how to invoke it. As rest of the part remains the same as in scenario (a).

InvokeHelloWorld.py

Invoke Function

Here, I need to pass “Name” as Input to the Integration.

Trigger In OIC

Scenario (c) –> Calling FetchEmpData Integration (with Single Input & Multiple Output parameters)

Here I will be covering only the Integration specific .py file and how to invoke it. As rest of the part remains the same as in scenario (a).

InvokeFetchEmpData.py

The only difference in InvokeFetchEmpData.py when compared to the previous files is the output variable.

Invoke Function

Here, I need to pass “EmpId” as Input to the Integration.

Trigger In OIC

Scenario (d) –> Calling FetchEmpDeptData Integration (with Multiple Input & Output parameters)

Here I will be covering only the Integration specific .py file and how to invoke it. As rest of the part remains the same as in scenario (a).

InvokeFetchEmpDeptData.py

Invoke Function

Here, I need to pass “EmpId” & “DeptNo” as Input to the Integration

Trigger In OIC

!!! HAPPY READING!!!

You can download the complete code from here https://github.com/santhoshbvsrk/OCIFunctions

If you liked the article, please like, comment, and share.

Please look at my YouTube channel for Oracle Integration-related videos and don’t forget to subscribe to our channel to get regular updates.

Further Readings

Scheduled parameters to maintain Last Run Date Time in Oracle Integration

How to Customize the Lock Screen in Oracle Visual Builder

Merging two CSV files into a single file in Oracle Integration

ERP Integration using File Based Data Import: Oracle Integration

Import Suppliers using FBDI in Oracle Integration

How to call Oracle SaaS ESS job using Oracle Integration