Webhooks, woocommerce, bubble & loops

Hi,

I need some help with webhooks, woocommerce and bubble.

I am attempting to take an order in woocommerce and create a thing (tag) in the bubble database for each item ordered. I have this working with a webhook and two api workflows, but come unstuck when multiples of the same item are ordered.

My wooCommerce webhook looks like this:

"line_items": [
    {
      "id": 112,
      "name": "item 1 - variation 1",
      "product_id": 2648,
      "variation_id": 2650,
      "quantity": 2,
      "tax_class": "",
      "subtotal": "25.98",
      "subtotal_tax": "0.00",
      "total": "25.98",
      "total_tax": "0.00",
      "taxes": [],
      "sku": "1"
      "parent_name": "tinytag"
    },
    {
      "id": 113,
      "name": "item 1 - variation 2",
      "product_id": 2648,
      "variation_id": 2652,
      "quantity": 1,
"tax_class": "",
      "subtotal": "12.99",
      "subtotal_tax": "0.00",
      "total": "12.99",
      "total_tax": "0.00",
      "taxes": [],
      "sku": "1"
      "parent_name": "tinytag"
    },

In that example, I end up with an entry in my order table like this:
Screenshot 2024-01-27 at 16.27.53

It then splits those items to two lines in the other table, when it should be three:
Screenshot 2024-01-27 at 16.29.08

My back end workflows look like this:
API workflow new_order

API workflow order_split

My question is, how would I create a new thing in my database for items when multiples of the same variation are ordered? Presume I need to do something with the line_item quantity, but then how do I get bubble to loop on the variation ID and quantity?

Really hope that makes sense! Thanks in advance.

Any ideas anyone?

Turn order_split into a recursive workflow. Here is a general outline on how it could be done:

Add a new input parameter called iteration (number).
As the last workflow step, use the action ‘schedule API workfow’ and re-schedule order_split, but input Iteration = Iteration + 1. On this workflow step, make sure to add the conditional ‘Order’s quantity > Iteration’. This will ensure that the workflow only runs ‘quantity’ amount of times. How you retrieve order quantity depends on you/your setup. You could also input another parameter called ‘quantity’ which always stays the same.

I managed to get it to work with something im calling a “nested recursive workflow”!

Thanks for the help.

Nested loop? :wink:

Haha yeah, a recursive workflow, inside another recursive workflow!