Skip to main content

Overcoming Upsert Limitations: A Case Study on Enabling Upsert Operations in APIs without Inherent Support

Various kinds of APIs are accompanied by diverse approaches. Record creation, updating, and deletion capabilities are offered by the majority of APIs. Some even suggest using the Upsert function, which combines Insert and Update. That is, new records can be added simultaneously with the ability to edit current records.

In the absence of Upsert functionality within the API, users won't engage in the repetitive creation of multiple bridges. This guide will specifically explore this scenario wherein the API lacks Upsert capability and how using eZintegrations, this problem is getting resolved. In this use case, we will show the integration between API to API.

Step 1: Select Source as API and along with Product name and business object.

Step 2: Add the API details along with the additional details if any (like Headers, Body, Pagination, etc). Using Test button, check the API response.

Step 3: Click Next and go to Operations.

In this scenario, to come up with the Upsert Action, we have used API operation and completed the Upsert Action in two steps.

Singleline to Multiline

Singleline to Multiline is used for converting the single-line JSON data into a multiline format.

Below is the format for singleline to multiline.

['bizdata_dataset_response']['data']

API Operation

This operation acts as a mode of data transmission. Details in the API operation is added similarly as it is done in Source and Target as API. 

Rename

To ensure the keys don’t overlap each other, we have used rename operation and changed bizdata_dataset_status to api_status.

Format for using rename operation:

"bizdata_dataset_status":"api_status"

Filter Operation

If else is called as the filter operation in eZintegrations, basically it has 1 parameter: Conditional Statement.

·       Source has the JSON data of the previous operation.

·       Target is the JSON data after performing the filter operation

·       Conditional Statement is the parameter where we include logical operators (and, or, not), Identity operators (is, is not), membership operators (in, not in), comparison operators (==,!=, >,  <, <=, >=)

Within this process, we apply a filter operation to sort and extract records based on specific user-defined conditions.

Here, we have two conditions for which we will be applying the Filter.

Condition 1: Using API operation, firstly the records will get inserted based on the condition if the response is not equal to 200, insert the records. Therefore, the API used in this operation will be for Insert.

Example: The condition for applying the insert records will be written as:

data['api_status']!='200'

Append

Using Append the new column will be created, which will show the status of the record, whether the record is inserted or updated.

Append key-value pair will be:

record_action: "Insert"

Filter Ends

This will end the condition for first filter operation.

Filter Operation

In this operation, we will apply the second condition for the use case.

Condition 2: When the response is equal to 200, update the record in the target. 

Example: The condition for applying the update records will be written as:

data['api_status']=='200'

Append

Using Append the new column will be created, which will show the status of the record, whether the record is inserted or updated.

Append key-value pair will be:

record_action: "Update"

Step 4: Once all the conditions have been provided along with the required operations for transforming the data to send to the target, we will then click on Next and go to target.

Step 5: Select the Target as API and required product and business object. In this step, we will use the Update API for updating the records in the Target.

Once all the required details are added, click on Submit to complete the connection between two APIs and integrate the data for Upsert Action.