This is a common requirement where we need to transfer files using OIC integrations.
These files can be transferred for example as octet-stream or multipart/form-data etc.
In this post we will see how we can send file using multipart/form-data in OIC integration.
Let us take example where we want to use OIC Rest API to export integration from one instance and import to target instance using an OIC Integration.
The OIC rest APIs can be found in below link:
https://docs.oracle.com/en/cloud/paas/integration-cloud/rest-api/index.html
For our example We will be using below operations:
Retrieve Integrations
Export an Integration
Import(Add) an Integration
Let us create connections in OIC using rest adapter :
create one connection for source instance and other for target instance
Below is connection for target env:
We can have the url as per our requirement:
for eg:
https://abcd-xyz.integration.ocp.oraclecloud.com/ic/api/integration/v1
or
https://abcd-xyz.integration.ocp.oraclecloud.com/ic/api/integration
or
https://abcd-xyz.integration.ocp.oraclecloud.com/ic/api
or
https://abcd-xyz.integration.ocp.oraclecloud.com/ic
or
https://abcd-xyz.integration.ocp.oraclecloud.com
If we use for eg the last one then while configuring rest adapter in the integration we need to prefix:
/ic/api/integration/v1 along with the endpoint resource.
Below is the sample for source env connection:
Now let us create the integration :
Here in our example we are fetching only active integrations from the source env , so we will be using query parameter to filter the records while getting the list of integration. If we want to fetch all then we don't need to have the query parameter.
Note:- if we are fetching all integrations and if the total integration number is too high then we might need to use offset and limt.
We can customize the fields we want and remove other fields which we don't want.
There will be many other fields like connection details, links etc which we don't need so we can have sample response payload like below.
Below is the mapper for above configured adapter:
This will give us list of all the activated integrations from source instance.
Now let us have a for each loop for each integration to export from source and import the integration to target env.
We can process them in parallel by checking the check box, which would do our job quickly.
Now let us configure the rest adapter for source env connection to export the current integration in loop:
Below is the mapper for exporting integration:
If we observe we have used like this:
concat (substring-before ($CurrentIntToExport/nsmpr1:items/nsmpr1:id, "|" ), "%7C", substring-after ($CurrentIntToExport/nsmpr1:items/nsmpr1:id, "|" ) )
We have used %7C for url encoding.
Now let us see the adapter configuration for importing the exported integration in previous step.
We need to do the mapping carefully and correctly otherwise it will give 400 bad request error.
Now let us see the mapper for this:
We need to mainly map below three fields:
Attachment Reference - Provide the stream reference from exporting integration response
Part Name - This will be the iar file name. We have used like below
concat (translate ($CurrentIntToExport/nsmpr0:items/nsmpr0:id, "|", "_" ), ".iar" )
fileInputHtmlFieldName - For this we need to give value as 'file'
In our case the target system is configured to read from a body part having name="file" in its content disposition. This is done with the fileInputHtmlFieldName element.
The target system may also be configured to read from a body part having name="image" in its content disposition. in that case we need to provide 'image' to fileInputHtmlFieldName.
The fileInputHtmlFieldName element is important to consider if the target endpoint expects
attachments under a specific body part name.
The body part name should be specified here.
For example, in our case in the import integration operation, the target endpoint is expecting an iar document under a body part named file in the multipart/form-data request payload.
Now let us run the integration and see the payloads and result:
For testing We have used a new Env where we do not have any integrations.
Now lets run the integration:
Message sent to get activated integrations from source instance:
Now lets open message received from get activated integrations:
Message sent to import int:
Now we can also verify from the target Env:
No comments:
Post a Comment