How to capture order history using Zapier (or another similar program) in the JSON-file? Answered

Post author
Michel Arriagada

Hi!

I need to capture my customers order history. I began using Zapier, but I have no particular reason for choosing Zapier over say Make.

Now, I managed to easily capture all the order information that Webflow sends, along with the unique member ID for logged in members. This allows me to identify each member, as well as all the information about their order.

My idea is to save it to the JSON, and pull that information into a field in logged in customers Order History-page.

What I don't understand is how to structure the code to the JSON in Zapier. I've tried a few different placements, but I have no idea how to place the information so that it saves the information, and that it saves it in a hierarchical manner similar to this:
Order ID
 - Items
    - Item count, item name, SKU etc...
 - Date of placed order

How do I write this in Zapier?

Comments

1 comment

  • Comment author
    Chukwudi Onyekwere
    • Official comment

    Hey!

    I’d recommend working with our AI bot, Rey or possibly, any other AI bot of your choice to achieve this. I did throw your question into our Rey, and here’s the response I got — you might want to give it a try or tweak it further to suit your needs:

    Steps to Structure Your JSON in Zapier:

    1. Set Up a Zap:

      • Begin by creating a Zap that triggers whenever an order is placed in Webflow (you’re already capturing order data from Webflow).

    2. Add "Code by Zapier" Action:

      • After receiving the order data, add the "Code by Zapier" action. This allows you to run JavaScript, which is perfect for structuring your data into the desired JSON format.

      • Select the "Run JavaScript" option.

    3. Structure Your Data with JavaScript:

      • In the "Input Data" section, map your Webflow order details (like order ID, items, date) to variables in your JavaScript code.

      • Here’s an example to help you structure your JSON:

    Example JavaScript Code:

    const orderID = inputData.orderID;  // Order ID from Webflow
    const items = inputData.items;      // Order items data from Webflow
    const orderDate = inputData.orderDate; // Order date from Webflow
    
    // Create a JSON structure that represents your order history.
    const orderHistory = {
      order_id: orderID,
      date_placed: orderDate,
      items: items.map(item => ({
        item_count: item.itemCount,
        item_name: item.itemName,
        sku: item.sku
      }))
    };
    
    // Return the structured JSON object
    return { order_history: orderHistory };
    
    1. Map the Data in Zapier:

      • In the Input Data section, map the variables from Webflow (like orderID, items, and orderDate) into your JavaScript code.

    2. Save the JSON Data:

      • After structuring the data in JSON, you can save it in your database or pass it into the next action in your Zap. This JSON will be used to populate the order history on your customer's page.

    3. Test Your Zap:

      • Finally, test your Zap to ensure everything is working smoothly. The output from the code step will contain your structured JSON, which you can use in the following actions.


    Example of a Hierarchical JSON:

    If the Webflow order data looks like this:

    {
      "orderID": "12345",
      "orderDate": "2025-04-03",
      "items": [
        {
          "itemCount": 2,
          "itemName": "T-shirt",
          "sku": "SKU123"
        },
        {
          "itemCount": 1,
          "itemName": "Jeans",
          "sku": "SKU456"
        }
      ]
    }
    

    The output after Zapier’s processing will look like:

    {
      "order_id": "12345",
      "date_placed": "2025-04-03",
      "items": [
        {
          "item_count": 2,
          "item_name": "T-shirt",
          "sku": "SKU123"
        },
        {
          "item_count": 1,
          "item_name": "Jeans",
          "sku": "SKU456"
        }
      ]
    }
    

    Recap:

    • Input Data: Map Webflow’s order information to variables in your JavaScript.

    • JavaScript Code: Build a JSON object that organizes the data hierarchically.

    • Save or Use JSON: After structuring the JSON, use it in the next steps of your Zap, whether it’s saving it to the customer’s profile or displaying it on the Order History page.

    Hope this helps clarify things!

Please sign in to leave a comment.