Skip to main content

Map Product Data from Shopify

Learn how to use data mappers and loops.

Introduction

In this guide, we are going to build a flow that showcases the data mapping capabilities of the fastn platform.

Prerequisites

  • A Shopify account is required with a store setup and some products added as we are going to retrieve products for export.

Part I - Getting Data from Shopify

Activate the Shopify connector

  • As a first step, we need to activate the Shopify connector so that it can be authenticated and linked to the store from where we want to fetch our products.

  • To activate the connector go to the Connectors page from the navigation menu on the left.

  • Go to fastn connectors and find the Shopify connector.

conn-1

  • Click on the Activate button and fill in the parameters for the store name.

conn-1

  • To get the store name, go to your Shopify store and copy the store name from the URL like shown below.

conn-1

  • The authentication will then redirect and ask for permissions. Click on Install.

conn-1

  • After activation the connector status will update.

conn-1

Create a new flow

  • To start off, go to the Flows page from the left side menu, and add a new flow.

flow-page

  • Give your flow a name and create it as an API.

flow-creation-menu

Get products from Shopify

  • Drag and drop a connector element. Choose fastn connectors and find Shopify.

conn-1

  • Choose the Get Products API.

conn-1

  • Once the connector configuration opens up. Click on the Disconnected label next to the icon and select the Default option.

  • Click on Connect and the connector status will be updated to Connected.

  • Setup the connector parameters as in the image below. In this example we set the limit to 10 but it can be set to suitable alternate values or can be set through the flow input.

conn-1

Part II - Mapping Product Data

  • Drag and drop a Variable step. Add a new field as a list and name it mappedProducts. This variable is going to store the results of the data mapping process.

var-1

var-1

  • Add a Loop step and set the Loop Type as Loop Over Data and Loop Data as {{steps.getProducts.output.products}}. This loop will iterate over each product in the output of the getProducts API.

loop-1

loop-2

  • Navigate inside the loop by clicking on View Loop Flow.

  • Drag and drop a Data Mapper element and name it as mapProduct.

map-1

  • For the purposes of this example we are going to add four fields in the data mapper namely id, title, and status.

map-1

  • The id field will be used to store a new unique id for each product. To do that, we will configure it as a random UUID. Click on the three dots to view additional options and select Advanced Actions. Select the UUID action and click Save.

map-1

  • The title field will hold the title of the product. So we will assign it {{steps.loopOverProducts.loopOverItem.title}} as the value.

  • In each loop, the loopOverItem represents the object being looped over and can be used to access its properties like we did above.

  • The status field will be used to record a custom status based on a condition. We will configure a condition that checks if the status of the product is active we will map it to the value LIVE and in all other cases we will map the status to the value DRAFT.

map-4

  • Click on the three dots and select Advanced Actions. Select the Condition action and add a new condition to check if {{steps.loopOverProducts.loopOverItem.status}} is == to active. Return value should be LIVE.

  • Use the + button next to Condition to add a second condition and set it up to check if {{steps.loopOverProducts.loopOverItem.status}} is != to active. Return value should be set to DRAFT and save.

  • Save the data mapper and add a Variable step after it. Add a new field as a list and name it mappedProducts. We will setup this step to insert the mapped data into the mappedProducts variable we defined outside the loop.

map-5

  • Click on the three dots and select Advanced Actions. Select the Insert-Item action and set it up to select the {{var.mappedProducts}} as a list and add {{steps.mapProducts.output}} which holds the mapped product as an item on each iteration of the loop.

map-6

  • Save the step and exit the loop.

  • Finally, we are going to add a Success element and output the mapped products using the variable {{var.mappedProducts}}.

success-1

success-2

  • We can use the Debugger to test the complete flow by clicking on the button on the top right and then clicking the play button to run the test. The output will represent the mapped products.

flow-1

Mission Success

Congrats on following this guide to the end!