Copy the Auth callback URL, and Load callback URL from Gadget to your BigCommerce app
Select the Products Read-only OAuth scope and click Update & Close in the BigCommerce app
Step 3: Set up client credentials and install on a sandbox store
Finish connection setup by copying the client credentials from BigCommerce back to Gadget and installing the app on a sandbox store.
Click View Client ID for your new app in BigCommerce and copy the Client ID and Client Secret to Gadget, then click Continue
In your BigCommerce sandbox store, navigate to Apps → My Draft Apps, hover over your newly added app, and click Learn more
Click Install
Congrats, you have successfully installed your app on a BigCommerce sandbox store!
The frontend you see is your Gadget app's React frontend built with the BigDesign library and embedded in the sandbox store.
You will also have a new data model at api/models/bigcommerce/store that holds data for the BigCommerce sandbox you installed your app on.
Connection complete!
Gadget takes care of the boilerplate that goes into setting up full-stack BigCommerce apps. By setting up the connection, you have done the following:
set up a full-stack application
handled BigCommerce OAuth and callbacks for a single-click app
created a bigcommerce/store data model and saved the store data
taken care of frontend session management with the session model
installed the BigDesign library for your React frontend
Step 4: Subscribe to BigCommerce webhooks
BigCommerce webhooks are available as triggers on global actions.
To subscribe to BigCommerce webhooks:
Navigate to /api/actions in Gadget, click +, and create a new action named handleProductCreate.js
Click + in the Triggers card in your action and select BigCommerce
Select the store/product/created webhook scope used to trigger the action
The action will now be run when the webhook is triggered.
BigCommerce webhook payloads only include the id of the resource that triggered the webhook. To fetch the full resource data, you can use the included BigCommerce API client to fetch the resource data in the action.
Copy-paste the following code into the action file:
13 logger.info({ product, params },"product data and webhook payload");
14};
15
16exportconstoptions:ActionOptions={
17triggers:{
18bigcommerce:{
19webhooks:["store/product/created"],
20},
21},
22};
To test the webhook, create a new product in your BigCommerce sandbox store.
You should see the product data logged in the Gadget Logs.
To learn more about subscribing to BigCommerce webhooks, see the webhooks guide.
Step 5: Save the BigCommerce webhook payload
Now you can store that BigCommerce product data in your database so you can use it in your app.
Right click on api/models/bigcommerce, select Add model, and create a new product model
Navigate to api/models/bigcommerce/product/schema and add fields to the model with the following validations:
Field name
Field type
Validations
bigcommerceId
number
Uniqueness, Required
name
string
Required
store
belongs to
Note: The store field is a belongs to relationship to the bigcommerce/store model. This is used to associate the product with the store it was created in. The inverse of the relationship should be a has many so that bigcommerce/storehas manybigcommerce/product.
You can add more fields as needed, or remove fields you don't need! It is a good idea to only store the data required to power your app.
Update api/actions/handleProductCreate.js to save the product data to the database:
23 logger.info({ product, params },"product data and webhook payload");
24
25// store product data in the product data model
26await api.bigcommerce.product.create({
27bigcommerceId: product.id,
28name: product.name,
29store:{
30// get the bigcommerce/store id for the record stored in Gadget
31_link: connections.bigcommerce.currentStoreId,
32},
33});
34};
35
36exportconstoptions:ActionOptions={
37triggers:{
38bigcommerce:{
39webhooks:["store/product/created"],
40},
41},
42};
Create another product in your BigCommerce sandbox store and open api/models/bigcommerce/product/data to see your saved product data
Every time you add a product to your BigCommerce sandbox store, the product data will be also saved to your Gadget database!
For more information on working with data in BigCommerce, see our data guide.
Congrats! You have learned how to start building BigCommerce apps in Gadget!
Next steps
Now that we have set up a BigCommerce connection and learned how to subscribe to webhooks and store data in a Gadget database, you can start building a single-click app!
Check out our tutorial for building a full-stack, single-click app that automatically adds search keywords to products: