Iterate through array results and store results in Data-Store

Hi pipedreamers,

I’ve tried to script-kiddy my way through it with use of previous help topics, but I’m kind of stuck due to lack of node.js knowledge my side.

I’ll try to simplify my request for the sake of clairity.
Let’s say I receive a webhook with an array of data (e.g. item details of a shoppingcart). I want to loop through the array and store some data for each item with some basic join / concatenation into Data-Store.
For my next step I want to fetch that data from my Data-Store, use it and empty the Data-Store awaiting the next webhook arrival.

  • I’m aware of (data-store) performance issues. I anticipate on about one to ten array items for each run/webhook, I guess performance will be fine.
  • Yes, I know this github topic, it is working but not quite what I’m looking for
  • This topic might help me on my final step, but I’m not there yet.

So for example, my webhook gives me the following details for every single item within steps.trigger.event.body.order.products.resource.embedded

  • steps.trigger.event.body.order.products.resource.embedded[0].articleCode
  • steps.trigger.event.body.order.products.resource.embedded[0].quantityOrdered
  • steps.trigger.event.body.order.products.resource.embedded[0].productTitle
  • steps.trigger.event.body.order.products.resource.embedded[0].variantTitle

Into Data-Store key embedded[0] I want to join/concatenate the related data as “quantityOrdered | articleCode | productTitle | variantTitle” as a single value.
I want the same thing for all remaining items (embedded[1],embedded[2], etc etc)

In my final step I want to retrieve all data from the Data-Store, spit it out as single Telegram message.

I guess what I’m asking for will be a piece of cake from some of you, wizards as you are. Who wants to help me out?

Cheers!

Hi @pipedreamcom-sledge

First off, welcome to the Pipedream community. Happy to have you!

Sounds like you’re trying to transform each line item in an order as a webhook from your eCommerce platform.

Just as a side note, Data Stores can store any JSON serializable data. Since your order is incoming as JSON data to your workflow, you could potentially just store the entire payload.

But, it sounds like you need a specific transformation.

I recommend using the Array.map function in Javascript to iterate over each product in your order, and create the string of data that you need.

This is just a pseudo-example:

steps.trigger.event.body.order.products(product => Object.values(product.resource.embedded).join(' | '));

The Object.values() function will return an array of values of the resource.embedded object in each line item. Then you can .join() them together into one string.

Thank you for your reply @pierce , much appreciated.

Do I interpret your reply correctly by rewording it as “Skip Data-Store completely, get your data within a single step in the same flow”?

Interesting and funny at the same time, as that approach is exactly how I started my search for iterating over the data. Seems I got full circle now and exactly where I wanted to be.

I’ll give it a go tomorrow and come back to you. Thanks again!

Sledge