How to loop through an array, rename fields, and create a new array with modified fields in Make?

What are you trying to achieve?

Hi, I’m new to Make and need some help with setting up the following scenario:

I have a Shopify module that captures new orders from my Shopify store. Retrieved object contains line_items[] array from the order, and I need to loop through this array to transform the data into a new structure that will be passed to the BaseLinker module.

I need map these Shopify fields from the line_items[] array:

  • variant_id
  • product_id
  • quantity
  • price
  • name
  • sku

Into BaseLinker products[] array:

  • product_id
  • variant_id
  • name
  • sku
  • price_brutto
  • quantity

I think the only field that needs changing is the price field, which should map to price_brutto in BaseLinker. However, I’m not sure if it’s possible to pass all the existing fields as-is and only modify the price, or if it’s necessary to create a new array with the required structure for BaseLinker.

Here are data examples:
Shopify order:

{
  "order_id": 111111,
  "line_items": [
    {
      "variant_id": 123456,
      "product_id": 654321,
      "quantity": 2,
      "price": 50.00,
      "name": "Product A",
      "sku": "PROD-A"
    },
    {
      "variant_id": 789012,
      "product_id": 210987,
      "quantity": 1,
      "price": 100.00,
      "name": "Product B",
      "sku": "PROD-B"
    }
  ],
}

Wanted structure for BaseLinker:

{
  "order_id": 111111,
  "products": [
    {
      "product_id": 654321,
      "variant_id": 123456,
      "name": "Product A",
      "sku": "PROD-A",
      "price_brutto": 50.00,
      "quantity": 2
    },
    {
      "product_id": 210987,
      "variant_id": 789012,
      "name": "Product B",
      "sku": "PROD-B",
      "price_brutto": 100.00,
      "quantity": 1
    }
  ],
}

Can anyone guide me on how to achieve this? Many thanks!

Use an Iterator, to split out the Shopify line items, and then use a JSON Aggregator after your Iterator based on the BaseLinker data structure for products

Hello @nephring,
Check my scenario blueprint. create a new scenario and import it.
Parse Json and change key_make_blueprint.json (7.2 KB)

Preview of full scenario.

Preview of JSON Aggregator

Preview of Output

I hope this helps.
:+1:

Such a great community! Thanks a lot, it works perfectly!

Now I think I need some advice on how to pass all the necessary variables to the BaseLinker module.

To get all the required data, I split the scenario into two paths:

  1. Passing unchanged and necessary data directly from Shopify to the BaseLinker module.
  2. Modifying line_items[] using iterators.

However, I’m having trouble linking the Array Aggregator directly to the BaseLinker module. It seems like the module expects a single data source. Is there a way to merge these two paths into one again so that all the required data is available for BaseLinker? Or maybe there’s another better way to achieve this?

Thanks again for help!

Hello @nephring,
When you use a Router, every route has its own set of processes and data when you go on.
However, there is one solution to use the previous route to process data into the next route.

Use the “Set Multiple Variable” at the end of the route. https://www.make.com/en/help/tools/tools#set-multiple-variables

Then the start of the next route use “Get Multiple Variableshttps://www.make.com/en/help/tools/tools#get-multiple-variables

Now in your case, set the variable after Array Aggregator, Then call that variable back at the start of the another route using “Get Multiple Variables” and use it on BaseLinker.

Also, make sure to cross-check variable names.
I hope this helps.

Mhm.

I’m not sure I fully understand the part about Get Multiple Variables.

Where exactly should it be placed? In the second path, I don’t seem to have access to the saved variable Order products from the Set Multiple Variables module.

You did it right.
Just for cross-checking (testing) unlink your BaseLinker module and just run the scenario.

See what result you get for Get Multiple Variables. If it’s ok then
Relink BaseLinker module again ⇒ Setup appropriate values
Then run it again.

1 Like

yes, you’re right. I have issue with variable names. Now it works great.

Big thanks for helping again, problem solved.