Map function is aggregating the values into a single string instead of creating separate objects for each SKU

Hi again Community!

My objective is to take orders from my Shopify store, split each SKU in that order and match against additional row data in Google Sheets, and then aggregate that data back into a single bundle to pass to the HTTP module API back to my supplier.

Steps in my Flow:

  1. Shopify Webook to Watch Orders: Captures new orders.
  2. Iterator: Splits the array of line items.
  3. Google Sheets Search Rows: Matches each SKU from the order to the SKU in Google Sheets and retrieves additional data against that SKU.
  4. Array Aggregator: Aggregates the matched results into a single array.
  5. HTTP Request: Sends the aggregated data to the API.

Issues:

  • After I aggregate the data back into a Bundle, I get a collection for each SKU in that order (see screenshot). This is good, because I want to send the order with all the skus as one API call.
  • In the HTTP module, I have an array called items where each item has a basic structure of SKU and Details.
  • When I reference the aggregator for the SKU and the details, it only returns the first collection (i.e., the first SKU in the order).
  • I then tried to use the map function with the raw value, to get all the SKUs and their details in the order (see screenshot).
  • However, the map function concatenates the values as strings instead of treating each SKU order as its own object.

Desired Output:

In my API, I want the basic structure of:

"items": [
  {
    "sku": "SKU 1",
    "details": "SKU 1 Google Sheet Matching Details"
  },
  {
    "sku": "SKU 2",
    "details": "SKU 2 Google Sheets Matching Details"
  }
]

Current Output:

What I am getting instead is:

"items": [
  {
    "sku": "SKU 1, SKU 2",
    "details": "SKU 1 Google Details, SKU 2 Google Details"
  }
]

Screenshots:
The Flow

The Aggregator turning multiple Bundles into one with a collection for each SKU

How I am using the map function to get to all the SKU (one in each collection from the Aggregator )

Example of the HTTP concatenating each collection into the same line instead of repeating it as an object (please note it while it looks like it printed the same SKU twice, they are actually different SKU, one from each collection, due to the row matching from Google Sheets).

Any error messages: No error messages, but incorrect concatenation of SKU values.

Additional Context:

  • I have ensured that the Iterator splits items correctly.
  • Verified that the Google Sheets Search Rows module uses dynamic SKU from the iterator.
  • Ensured that the matching works, and the API receives data from both the Shopify module and the matched row.

Any advice on ensuring all SKUs are processed correctly and outputted as separate objects within the items array?

Thank you!

You’ll need to iterate each array and create the json you want structured. Or try the Transform to JSON module in the JSON app which may do a better job for you from the array you got from the aggregator then you can take that resulting text and stuff it into your overall http json.

The concatenation is the natural thing that happens due to the fact you are casting an array directly into text in your json and make simply does an internal join() function on your text ignoring the fact you want to create multiple collections from each sku.

2 Likes

Thanks to Alex’s advice above and then engaging with one on one help with Alex, this flow now works. I’ll post the solution below for the community to learn from. Huge thanks to Alex.

Here is the new completed flow

An iterator was added after the aggregator

This was done to separate out the SKUs into bundles. All the information for each SKU is now found in the Value collections.

Then a Transform to JSON from those Value collections

Then a Parse JSON

Then a Text Aggregator to get the part of the JSON in the array in the format I need

Finally this is how It is added back into the array, with the nested functions to prevent the last item in the array ending with a comma, so that the JSON remains valid.

3 Likes

@RK took is up on our Make Hero program and got a solution quickly and efficiently. Thanks for working with me!

1 Like