This is a three part series. It is about using Apex for integration work. It was presented at Oracle User Group Norway (OUGN) on the 15.05.25. The first part focuses on creating your own REST service. This service retrieves data from a third party and stores it in Apex. Later, we will relay it to Oracle ERP.
The Second part will detail how to use Oracle ERP integration service to upload data. In this example we will upload currency data to ERP. The third part will be about how to use Oracle Workflow to orchestrate the integration.

ERP Integration Service is a great service that can do almost any integration against ERP Cloud. If there is a REST or SOAP service that can do the job, of course I prefer that. But sometimes the REST and SOAP services in Oracle ERP can have limitations, that ERP Integration service don’t have.

Creating the REST API








In the code above some of the code for the rest service can be viewed. Some of the SQL bind variables, like :body_text and :status_code, are implicit variables. They can be assigned and referenced without any declaration. List of implicit parameters below.

We will use the :body_text, :status_code and the declared parameter :errmsg in this integration.

When returning from the procedure call we check the status code. If it’s 201 we return the batchid for the callers reference. If any exceptions occur inside the procedure we return 400 and the error message.
The callback service

The above service is open, but protected with the JSON token. A random caller trying to call this service will struggle a lot. They will find it difficult to understand how to call this service. Generating a valid token is also challenging. I think it’s possible to set up SAML authentication also. I have not figured out how to do that yet. Will for sure blog about it, if I find out.
Creating an Oauth client for the dailyRate service.

We will go here to create the Oauth client to authenticate against the dailyRate service.





Receiving the currency payload via our REST api
The payload will be of type JSON.
{
"operationName": "uploadCurrencyData",
"sourceRef": "241e89df-073f-48b1-88ac-88546370e4aa",
"rates": [
{
"fromCurrency": "GBP",
"toCurrency": "NOK",
"fromConversionDate": "2024/03/19",
"toConversionDate": "2024/03/28",
"userConversionType": "Spot",
"conversionRate": 13.550361599999999999999999999,
"inverseConversionRate": 0.0737987685878434417573033623
},
{
"fromCurrency": "SEK",
"toCurrency": "NOK",
"fromConversionDate": "2024/03/19",
"toConversionDate": "2024/03/28",
"userConversionType": "Spot",
"conversionRate": 1.00,
"inverseConversionRate": 1.00
},
{
"fromCurrency": "CAD",
"toCurrency": "NOK",
"fromConversionDate": "2024/03/19",
"toConversionDate": "2024/03/28",
"userConversionType": "Spot",
"conversionRate": 7.8543095185430951854309518543,
"inverseConversionRate": 0.12731863923100030039050766
},
{
"fromCurrency": "CHF",
"toCurrency": "NOK",
"fromConversionDate": "2024/03/19",
"toConversionDate": "2024/03/28",
"userConversionType": "Spot",
"conversionRate": 11.997747494087171978826444419,
"inverseConversionRate": 0.0833489786722739561429858816
}
]
}



When payload is parsed, inserted and committed the p_status_code will be set to 201-created. On commit a trigger will evaluate a lot of currency rules. If an exceptions occurs, insert will roll back and p_status_code will be set to 400-error.
Oracle ERP enforces these rules for a currency payload:
Code Description
VF01 The Rate Type is invalid.
VF02 Date range between the From Date and To Date should not exceed 366 days.
VF03 The Conversion Rate must be a positive number.
VF04 The Inverse Conversion Rate must be a positive number.
VF05 The From Currency is invalid.
VF06 The From Currency is disabled.
VF07 The From Currency can not be STAT (statistical).
VF08 The From Currency is out-of-date.
VF09 The From Currency can not be an EMU currency.
VF10 The To Currency is invalid.
VF11 The To Currency is disabled.
VF12 The To Currency can not be STAT.
VF13 The To Currency is out-of-date.
VF14 The To Currency can not be an EMU currency.
VF15 Duplicate Row (an overlapping date range was found).
VF18 Self Rate Row not allowed.
All of these rules are enforced in foreign key constraint, unique constraints and trigger code. When third party call out service they will get immediate feedback on the payload. Our service is synchronous service while the Oracle ERP service is asynchronous.




That was the end of part I. We have created two REST services. Made a Oauth client and tested it. We have implemented the daily rate service with tables, package routine for inserting and a trigger for validating the currencies.



Leave a Reply