How to loop through all items in a new order based on quantity?

Hello,

I have a flow that checks whether the customer has purchased a gift card based on the variant ID.

If they have, then the flow sends an API request to generate the gift card code and email the customer.

This works well when there are different gift card amounts in the same order, ie $10 and $15, as these are different variant IDs.

The customer receives 2 emails, one with a code for $10 and one with a code for $15.

However, if someone orders two or more $10 gift cards, the flow only runs once and the customer only receives one code when they should be getting two codes for $10.

How can I make it so the flow runs for the quantity of items ordered? IE if someone orders five $10 gift cards, the flow should run five times and not just once.

Hopefully that explains it clearly enough, any help appreciated!

1 Like

I would rather try to avoid modifying the 3rd party API if at all possible. Is there really no way to handle this just with Shopify Flow alone?

Not looking for ChatGPT answers, real developers only please. Thank you.

1 Like

The lineItem object also includes the currentQuantity so this might be possible using a Run code action to script the number of codes to generate.