How to Create Two Related Things from a Single API Response

Hey everyone,

I’m making an API call to fetch order data from an e-commerce site. The response structure has two levels , where an order contains multiple order items. Here’s an example:

{
  "orderId": "123456",
  "customerName": "John Doe",
  "orderDate": "2024-03-03T12:00:00Z",
  "totalAmount": 150.75,
  "orderItems": [
    {
      "itemId": "A1B2C3",
      "productName": "T-Shirt",
      "quantity": 2,
      "price": 25.50
    },
    {
      "itemId": "D4E5F6",
      "productName": "Sneakers",
      "quantity": 1,
      "price": 80.00
    },
    {
      "itemId": "G7H8I9",
      "productName": "Baseball Cap",
      "quantity": 3,
      "price": 10.25
    }
  ]
}

I need to create two types of things in Bubble:

  1. Order (storing orderId, customerName, totalAmount, etc.)
  2. Order Item (storing itemId, productName, quantity, price and Order.)

I’m struggling with how to iterate over the order items and correctly associate them with the parent order in the database.

Any advice would be greatly appreciated! Thanks in advance.

I have found a solution by using a scheduling API on a list of orders and passing order items formatted as text with a delimiter as parameters to this API.

After that, I schedule another API call for a list of order items at the end of the order processing API. Finally, I use regex to extract the fields from the order items.

If you have a better solution, I would love to hear it.

Is there someone who knows the best and the most efficient method?