Blog
/
Product

Introducing a stateless Shopify integration: React to webhooks without saving data

Published
April 29, 2024
Last updated
August 16, 2024
Add webhook triggers to global actions to simplify data forwarding and avoid unnecessary data storage.
TL;DR: You can now add Shopify webhook triggers to global actions in Gadget.

As of today, Shopify webhooks are available as triggers for global actions, meaning you can build stateless applications with the ability to mutate data as it comes in. You no longer need to store every change to your database, so you can save on data storage costs. 

Before today, Shopify webhooks were only used for model actions, which meant that the webhook payloads were stored in the Gadget database and only targeted a single record. With this change, you can now use a webhook to trigger code in a global action, and therefore not store any of the data that is not required for an app’s functionality. Or, you could handle multiple records provided by the webhook payload, such as order line items. 

It is best to use webhook triggers for global actions when you want to run code that doesn't affect the state of your application or database. The stateless approach is ideal for systems integrations or use cases where you need access to the full webhook payload before it is broken into multiple records. For example, if you're building an integration to a fulfillment service, it might be easier to capture every product line item from the webhook payload and send it over to the third party fulfillment service, as opposed to reacting to each product line item record as it enters your database as you would with model actions

What’s the difference?

Unlike webhooks on model actions (the stateful approach), when using global actions, no data is saved to your database. 

Typically, model actions come with a nightly reconciliation that helps ensure that all changes are captured and your database is up to date. With global actions though, that reconciliation of data will not run as there is no data saved. This means that if you require 100% data fidelity, you may need to build additional logic or continue using model actions, as you cannot rely on Gadget to reconcile data on global actions.

How to use Shopify webhooks in global actions

To add a webhook trigger to a global action, start by selecting your global action in <inline-code>api/actions<inline-code> and click on the + in the triggers panel, then select Shopify webhooks. From there, you can select your preferred webhooks and the webhook payload will be found in the <inline-code>trigger<inline-code> object provided by the action context parameter.

You can select Shopify webhooks from the list of triggers
Once selected, choose the specific webhook you'd like to use

For more details on working with Shopify webhooks in global actions, you can check out our docs. If you have any questions or feedback, we’re always here to help over on our developer Discord.

Emma Hyde
Author
Riley Draward
Reviewer
Try Gadget
See the difference a full-stack development platform can make.
Create app

Introducing a stateless Shopify integration: React to webhooks without saving data

Add webhook triggers to global actions to simplify data forwarding and avoid unnecessary data storage.
Problem
Solution
Result
TL;DR: You can now add Shopify webhook triggers to global actions in Gadget.

As of today, Shopify webhooks are available as triggers for global actions, meaning you can build stateless applications with the ability to mutate data as it comes in. You no longer need to store every change to your database, so you can save on data storage costs. 

Before today, Shopify webhooks were only used for model actions, which meant that the webhook payloads were stored in the Gadget database and only targeted a single record. With this change, you can now use a webhook to trigger code in a global action, and therefore not store any of the data that is not required for an app’s functionality. Or, you could handle multiple records provided by the webhook payload, such as order line items. 

It is best to use webhook triggers for global actions when you want to run code that doesn't affect the state of your application or database. The stateless approach is ideal for systems integrations or use cases where you need access to the full webhook payload before it is broken into multiple records. For example, if you're building an integration to a fulfillment service, it might be easier to capture every product line item from the webhook payload and send it over to the third party fulfillment service, as opposed to reacting to each product line item record as it enters your database as you would with model actions

What’s the difference?

Unlike webhooks on model actions (the stateful approach), when using global actions, no data is saved to your database. 

Typically, model actions come with a nightly reconciliation that helps ensure that all changes are captured and your database is up to date. With global actions though, that reconciliation of data will not run as there is no data saved. This means that if you require 100% data fidelity, you may need to build additional logic or continue using model actions, as you cannot rely on Gadget to reconcile data on global actions.

How to use Shopify webhooks in global actions

To add a webhook trigger to a global action, start by selecting your global action in <inline-code>api/actions<inline-code> and click on the + in the triggers panel, then select Shopify webhooks. From there, you can select your preferred webhooks and the webhook payload will be found in the <inline-code>trigger<inline-code> object provided by the action context parameter.

You can select Shopify webhooks from the list of triggers
Once selected, choose the specific webhook you'd like to use

For more details on working with Shopify webhooks in global actions, you can check out our docs. If you have any questions or feedback, we’re always here to help over on our developer Discord.

Interested in learning more about Gadget?

Join leading agencies making the switch to Gadget and experience the difference a full-stack platform can make.