Due to scheduled maintenance, some areas of our site are currently inaccessible. Thank you for your patience.

Please reach out to sales@eonesolutions.com with any questions.

Back

Creating an incremental REST API data source

Published: Jul 24, 2023
Post Author Written by Maksudul Haq

This article is an example of how to create an incremental or change data source for WooCommerce REST API. Steps are similar for other REST API connectors like Magento, BigCommerce, ConnectWise etc. The outcome of this article is to export only new or recently modified WooCommerce orders to Excel.

Note: Steps are identical for SmartConnect.com, except coding needs to be in JavaScript.

Steps are identical for SmartConnect.com, except coding needs to be in JavaScript.

Configuration Steps

Create two new Global variables in SmartConnect.

for example, GBL_WOO_ORD_DATE and GBL_WOO_ORD_STAGE_DATE.

Set a default date values in ISO8601-compliant date format (2020-06-15T07:17:39).

Next, go to the Maintenance > WooCommerce REST connector > Data Source tab 

  1. Edit the List all Orders data source.
  2. Navigate to the Parameters
  3. Add new parameter key modified_after with value GBL_WOO_ORD_DATE.

Next, create a data source for the List all Orders.

  1. Data Sources > Bulk > Generic REST Data Source

Then create an integration process using the data source and set the destination Excel export file.

This process will work with any destination you choose.

Complete the Mapping destination of the integration.

  1. You must map at least 1 field to the target.

Switch to the Tasks

  1. Create a new Run Script task as a Task that runs before the map.
  2. Write a script to read the current system date, and format the date in the required destination system date format.
  3. Save the task.
 ' Get the current date and time
        Dim currentDate As DateTime = DateTime.Now

 ' Format the date according to CRM format
        Dim formattedDate As String = currentDate.ToString("yyyy-MM-ddTHH:mm:ss") & "Z"


       GBL_WOO_ORD_DATE = formattedDate

return true
// Get the current date and time
DateTime currentDate = DateTime.UtcNow;

// Format the date according to ISO8601
GBL_WOO_ORD_DATE = currentDate.ToString("yyyy-MM-ddTHH:mm:ss") + "Z";
return true;
// Get the current date and time
var currentDate = new Date();

// Format the date according to ISO8601
GBL_WOO_ORD_DATE = currentDate.toISOString();
return true;

Add a new Script Task to Tasks that run if the integration succeeds.

  1. Set the script value to update the GBL_WOO_ORD_DATE variable with the value of the GBL_WOO_ORD_STAGE_DATE
GBL_WOO_ORD_DATE = GBL_WOO_ORD_STAGE_DATE
return true
GBL_WOO_ORD_DATE = GBL_WOO_ORD_STAGE_DATE;
return true;
GBL_WOO_ORD_DATE = GBL_WOO_ORD_STAGE_DATE;
return true;

Next, move to the Variables tab and edit the GBL_WOO_ORD_DATE

  1. Make sure the Persist Run Value

With this option set the value saved at the end of the map run will be used on the next run.

Conclusion

With these settings configured the integration will capture the date and time the integration run started and save it to a temporary variable. If the integration completes successfully, the value of the temporary variable will be transferred to the variable used in the REST Data Source setup so it can be used as the starting date on the next integration run.

Feeling stuck? Get the support and guidance you need to help you power through any data challenge

We're on your integration team. Connect with our people and let us know how we can help you.