I have a Ruby on Rails app which uses the Shopify Ruby Template. The webhooks are currently configured in web/config/initializers/shopify_app.rb. I’m looking to migrate these to my TOML file. The current instructions I see for migrating are for apps using the GraphQL API. However, I do see methods in the ShopifyApp::WebhooksManager, like destroy_webhooks, which should be able to remove the existing webhooks before registering them again in the TOML file. Is this the correct method to use when migrating? If not, what is the protocol?
Moving those shop-specific webhooks out of config/initializers/shopify_app.rb and into shopify.app.toml is the right direction.
App-configured webhooks live in the TOML under [webhooks] and [[webhooks.subscriptions]]; once you deploy (shopify app deploy or your template’s npm run deploy), Shopify registers them for every store where your app is installed (App configuration)
For cleanup, you’re correct that ShopifyApp::WebhooksManager.destroy_webhooks is the safe way to remove the old per-shop registrations.
I typically run a small task that iterates each installed shop with an authenticated session and calls destroy_webhooks, then remove any runtime webhook registration from the initializer so you don’t recreate them on next auth.
After that, rely solely on the TOML config and redeploy. You can confirm everything in your app’s Webhooks section or by firing a test delivery.
Shopify’s webhook docs give the broader context on behavior and delivery if you want to double-check expectations during the cutover (About webhooks)
In short: delete legacy shop webhooks via WebhooksManager, remove initializer config, define webhooks in TOML, deploy, and verify deliveries. If this solves it, marking as solution will help others find the path.
Thanks for the detailed response @Ruben_Stacksync!
Can you expand on this part?
I typically run a small task that iterates each installed shop with an authenticated session and calls destroy_webhooks, then remove any runtime webhook registration from the initializer so you don’t recreate them on next auth.
Is this a Rake task?
hey @chrismgala , I can’t speak to how @Ruben_Stacksync has set up his task, but you could set this up as a rake task or as a basic cron job if you’re not using Ruby. Essentially, you’d just query the existing webhooks for your app on the shop:
Then, run this mutation on each of the subscriptions as needed:
Hope this helps, let me know if I can clarify anything on my end here!
Hey folks
- just going to mark this thread as solved for tracking on our end here, but let me know if I can help out further.
Thanks for the advice everyone. I ended up completing the migration last night with a Rake task using the ShopifyApp::WebhooksManager.destroy_webhooks method.
shops = Shop.all
shops.each do |shop|
shop.with_shopify_session do
session = ShopifyAPI::Context.active_session
ShopifyApp::WebhooksManager.destroy_webhooks(session: session)
rescue => err
puts err.inspect
end
end
Glad to hear this solved the issue @chrismgala , and thanks for sharing your solution, really appreciated ![]()