Storing order data
Your marketplace is ready for merchants to start selling. You want 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 learnAnchor link to section titled "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
RequirementsAnchor link to section titled "Requirements"
Access scopesAnchor link to section titled "Access scopes"
Your channel app requires the following access scopes:
Step 1: Add the orders modelAnchor link to section titled "Step 1: Add the orders model"
In this step, you'll create an
Orders data table in your schema, with column data reflecting the information you want to store. You'll also run a database migration. For an overview of the available fields for generating your orders model, refer to the Order API reference.
Run the following command to create a new migration file:
In the newly-generated migration file, add the following code:
models/order.jsfile and add the following code:
Run the following to apply the migration and create the new data table:
Step 2: Add a webhook handlerAnchor link to section titled "Step 2: Add a webhook handler"
server/handlers/webhooks, create an
server/handlers/webhooks/orders.js, add a webhook handler to listen for incoming webhooks and save them to the
Ordersdata table that you created.
server/handlers/webhooks/setup.js, subscribe to the
Step 3: Register additional webhooksAnchor link to section titled "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.