Store order data

Your marketplace is ready for merchants to onboard and start selling. You want a way to save order data to your database for orders made on a marketplace through your channel app.

In this tutorial, you'll create a database table for storing order data. You'll also subscribe to webhook events and create handlers for them.

What you'll learn

After finishing this tutorial, you'll know how to do the following:

  • Handle webhook events for orders

  • Store order data in your database

Requirements

Access scopes

Your app will require the following access scopes:

  • read_orders

Step 1: Add the orders model

In this step, you'll create an Orders table in your schema, with column data reflecting the information you want to store. You'll also run a database migration.

Store the following values:

  • Shop domain (String)

  • Order ID (BigInt)

  • Order status URL (String)

Step 2: Add a webhook handler

In this step, you'll create the framework to subscribe to the ORDERS_CREATE webhook topic and handle orders/create webhook events.

  1. In server/handlers/webhooks, create an orders.js file.

  2. In server/handlers/webhooks/orders.js, add a webhook handler to listen for incoming webhooks and save them to the Orders database table that you created.

  3. In server/handlers/webhooks/setup.js, subscribe to the ORDERS_CREATE webhook.

Step 3: Register additional webhooks

There are several Order-adjacent webhook topics that you might want to subscribe to, and make database adjustments based on their content.

In this step, you'll subscribe to the ORDERS_FULFILLED webhook topic and handle orders/create webhook events.

  1. In server/handlers/webhooks/orders.js, add a webhook handler to listen for incoming webhooks and save them to the Orders database table that you created.

  2. In server/handlers/webhooks/setup.js, subscribe to the ORDERS_FULFILLED webhook.

Next steps

  • Learn how to bill merchants for sales they make on your marketplace.