API Flow’s advanced features
Business Problem
When your purchase order lines are in a different currency than your financial system, it can create significant challenges. With API Flow’s advanced features, API gateway, and ION we can create a solution that solves this problem.
Requirements
- Access to ION API Gateway
- Security role: IONAPI-Administrator
- Security role: IONAPI-User
- Knowledge of API Flow (loop)
- Knowledge of Python for scripting
- Knowledge of the module ION Connect
Tutorial
Difficulty: Medium
Estimated completion time: 30 Minutes
In the real world, integrating different systems using various technologies to exchange data is essential. This data must be seamlessly integrated and managed. Consider the integration of two systems using different currencies. With ION components, we can achieve this goal in just a few steps. See the below solution.
In this integration flow, three connection points (1,3,5), one scripting step (2), and one data merge step (4)
- A purchase Order is created by a procurement application and sent to Infor OS ION.
- XML to JSON (scripting) convert BOD to JSON object.
- Exchange Rate (API Flow) converts the PO lines amount into a different currency.
- Merge (Replaces the amount in currency produced by the API Flow).
- IngestToDataLake (Writes the BOD with the new currency values into DataLake).
The focal point is the connection point number (3) the API connection point that invokes an endpoint created with the API Flow.
API Flow with “DoWhile” component to iterate through the PO Lines
The API Flow is composed of Request and Response configurations where you specify the Input and Output format. As input, we have the Purchase Order BOD definition in JSON format, and as output, we have an array of the converted amounts for the Purchase Order Lines.
The first component in the flow is a JQ transformation that returns an array of amounts for each Purchase Order Line provided as input.
if .SyncPurchaseOrder.DataArea.PurchaseOrder.PurchaseOrderLine|type=="array" then .SyncPurchaseOrder.DataArea.PurchaseOrder.PurchaseOrderLine |[.[].TotalAmount] else .SyncPurchaseOrder.DataArea.PurchaseOrder.PurchaseOrderLine |[.TotalAmount] end
You can use this site https://jqplay.org/ for testing the JQ transformation.
The output of the JQ transformation is passed as input to the DoWhileTst flow that is formed by two steps, one more JQ transformation, and one API connector.
The JQ transformation (Objects) takes one element at a time from the received array and passes it to the API connector that invokes the Exchange Rate (Rate) endpoint for converting the amount into a different currency.
This is the output from the previous step,
{
"input": "${LineAmounts.output}",
"iterator": "${DoWhile1.output}.iteration"
}
that produce this result
[
{
"@currencyID": "AUD",
"#text": "4000"
},
{
"@currencyID": "AUD",
"#text": "5000"
}
]
and this is the JQ transformation to take one element of the array at a time,
.input[.iterator - 1]
For each element of the array, you take the currency value and the text value which is the amount of the PO line and you pass it as input to the Exchange Rate API.
The result is passed to another JQ transformation step that collects all results of the API call and sent them to the Output of the API Flow.
The Output contains an array of amounts converted in the currency specified in the Exchange Rate API call.
{"extractedOutput":[
{"amount":4000,
"base":"AUD",
"date":"2022-09-23",
"rates":{"EUR":2697.69}},
{"amount":5000,
"base":"AUD",
"date":"2022-09-23",
"rates":{"EUR":3372}
}
]}
The output of the API Flow, plus the original Purchase Order BOD are passed to the merge component, which uses an advanced merge type (scripting) to replace the original amounts value of the PO Lines with the value of the converted amount coming from the API flow results, producing a Purchase Order BOD with the PO Lines amounts converted in the new currency values.
The result of the merge flow is passed to the data lake ingest component that writes the BOD in Atlas.
Downloads
Resources
Online help documentation: