Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
Hi Shopify Community,
I hope you're all doing well! I'm currently working on handling subscription changes in my Shopify app and have encountered a scenario where the order of the 'app_subscription/update' webhooks becomes crucial.
Here's the situation:
The challenge I'm facing is that I cannot reliably determine the order in which these webhooks will be triggered. My application logic needs to know whether the cancellation webhook or the new activation webhook is called first.
How can I handle this scenario effectively? Is there a recommended approach or best practice for managing the order of these webhooks?
Any insights, experiences, or suggestions would be greatly appreciated. Thank you in advance for your help!
Best regards,
Umair Akram
Hi Umair,
In most cases, the webhooks are sent in the same order the events. However, due to network latency or other factors, you can't always guarantee the order of delivery.
Here's a suggested approach:
Timestamps: Each webhook includes a timestamp of when the event occurred. You can use this to reconstruct the precise order of events, regardless of when your app receives them.
Idempotency: Make sure your app handles webhooks in an idempotent manner. This means that no matter how many times your app receives a webhook, the result should be the same. For instance, if you receive a webhook for a subscription cancellation and then a new activation, your app should end up with the user having an active subscription.
State Checking: When your app receives a webhook, it can also make a GET request to Shopify's API to check the current state of the object. This way, even if you receive webhooks out of order you can still respond based on the current state of the object.
Try out the above to see if these strategies work,
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog