Merge two contents from two different API calls using InvokeHTTP processor
Introduction
This document illustrates how to merge two contents from two different API call’s by using the InvokeHTTP processor in Syncfusion Data Integration Platform.
Requirement Processor
Processor name | Usage |
Used to get data from server API calls. | |
Used to split the input data as multiple or separate content of the array element. | |
Used to store the attribute value from respected API call. | |
Used to replace the original data as per the FlowFile content. | |
Used to update the attribute value. | |
Workflow
Steps to merge two flow files:
Get data from web API-1 and store the attribute value
Step 1:
- Drag the InvokeHttp processor and configure the property field of HTTP method, Remote URL, and choose the StandardSSLContextService in SSL context service field.
- Set the required HTTP method (GET, POST) and specify API URL in Remote URL property field.
- Specify the time in Connection Timeout property field as per requirement.
- Configure the Keystore and Truststore filename and its password which you have it.
- You can create the truststore and keystore based on our domain. For more details, refer the following link - https://help.syncfusion.com/data-integration/how-to/configure-ssl-context-service-for-invokehttp-processor#steps-involved
- Map to next processor by choosing the Response field.
Step 2:
- Drag the SplitJson processor and configure the JsonPath expression field as per requirement.
- In this sample, you can split json as individual by giving this regular expression $.[*]. It helps to split json array as individual object.
- Map to next processor by choosing the split option.
Step 3:
- Drag the EvaluateJsonPath processor and choose the flowfile-attribute from the Destination property field.
- This processor is helpful to store the attribute value from respected API call. Here, it stores the attribute values from split json.
- By clicking the add button, you can include the properties in the configuration list.
- Specify the property value as $.<yourJsonPropertyName>.
Note:
For example, if you want to store the property values as attribute from json file, refer the tabulation as follows.
Sample Json | Property Name | Property Value |
Id name username website | $.Id $.name $.username $.website |
- Map to next processor by choosing the matched option.
Get data from web API-2 and store the attribute value
Step 4:
- Drag the InvokeHTTPProcessor and configure the properties as same as step 1.
- In the Remote URL field, specify the respected another web API URL and append the attribute value in same. You can specify any attribute name based on requirement.
Step 5:
- Drag the EvaluateJsonPath processor and choose the flowfile-attribute from the Destination property field.
- It’s same as Step 3, and add property field and value to store the attribute value from API call-2.
Merge data from API-1 and API-2 and store on local system
Step 6:
- Drag the ReplaceTextProcessor and configure the replacement value property field.
- Fill the saved attribute names from API call-1 and API call-2.
Replacement value in this sample as:
${id},${name},${username},${email},${phone},${website},${title},${url},${thumbnailUrl}
API Call | Attribute Name |
Attribute taken from web API call-1 | ${id},${name},${username},${email},${phone},${website} |
Attribute taken from web API call-2 | ${title},${url},${thumbnailUrl}
|
- Finally, you will get the above two contents as single response from different API call’s using this workflow.
Note: MergeContentFile processor is used to merge a group of FlowFiles together based on a user-defined strategy and packages them into a single FlowFile. Based on requirement, I would recommend this flow to merge two contents.
Step 7:
Drag the UpdateAtrribute processor to update the attribute value by adding the property as filename and value as any name with any extension type (optional) to store the file.
Step 8:
Drag the PutFile processor and configure the output directory path to store the merged content file in local system.
Note: Here, the output file has been saved as CSV. You can also build like a query import SQL server using the Putsql processor as per requirement.
Sample URL: