I’m currently building a Shopify app and have some struggles with webhooks. My webhook URLs are not updated.
I use the remix template. I start my server with shopify app dev --config <FILENAME>
Sometimes the webhooks work (mostly I need the order/create webhook) but sometimes they don’t.
I tried to start the server also with shopify app dev --reset and select my app in the CLI but that doesn’t help as well.
In my webhook dashboard, I see that they fail because they are arriving an old URL. What should be the typical way of starting the server so that the webhook URLs are also changed?
If it works I can see that the afterAuth hook is called. But when it is not working I can see that it is not working. I think they are simply not registered and therefore, have no updated URLs attached. But I don’t know why it won’t run.
You have correctly diagnosed the problem, if your app URL changes your webhook subscriptions in Shopify will also need to update for your events to be received.
This is generally only a problem for local development because in production your app URL won’t be changing.
For local development you have a couple of options
Don’t change your local development URL
You can supply your own tunnel to the Shopify CLI so that you can keep a consistent address for local development. Docs here.
Update the webhook subscriptions when your app URL updates
a) Trigger shopify.registerWebhooks({ session }); to run and update the webhook subscriptions.
If you are using the default template this is only run in the afterAuth hook. You could either call shopify.registerWebhooks somewhere else for local development, or delete the session/unistall to trigger the afterAuth hook to run again
b) Use webhook subscriptions defined in the shopify.app.toml (recommended)
Shopify has released a new way to manage app webhook subscriptions. Docs here.
If you are using this method, in another terminal while your app is running, you can run shopify app deploy to update the webhook subscription adresses in Shopify.
We by mistake made our webhooks go to https://https//url in prod
We fixed the URL, but 50% of the time, our webhooks are still arriving on the old URL, rest 50% of the time, we get it on the correct one.
I still didn’t understand the issue and how to solve it.
Where did you fix the URL, and how did you fix it?
If are using webhook subscriptions that are managed by the app, (defined in the ShopifyApp object.) Then you will need to update those subscriptions in Shopify. This would have to be done by making an API call to Shopify to update the address of the webhook subscription.