I've created a rails app with the shopify_app gem. I followed this guide to set up some webhooks. I made two webhooks in my shop admin, one for 'products/create' and 'products/update'. I made sure the API and Secret key from the app in my Partner account match the ones in the app. Then I generated two webhooks with
rails g shopify_app:add_webhook -t products/update -a https://my_url
When I change or create a product or when I use a test notification from the shop admin, this is what I get, with params and some other stuff redacted:
Started POST "/webhooks/products_update" for ***.***.***.*** at 2018-10-29 23:19:22 -0400
Cannot render console from ***.***.***.***! Allowed networks: *****************
(0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
↳ /Users/******/.rvm/gems/ruby-2.4.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
Processing by ShopifyApp::WebhooksController#receive as */*
Parameters: {......the product params}
Filter chain halted as :verify_request rendered or redirected
Completed 401 Unauthorized in 7ms (ActiveRecord: 0.0ms)
Started POST "/webhooks/products_update" for ***.***.***.*** at 2018-10-29 23:19:23 -0400
Cannot render console from ***.***.***.***! Allowed networks: ******************
Processing by ShopifyApp::WebhooksController#receive as */*
Parameters: {........the product params}
Filter chain halted as :verify_request rendered or redirected
Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)
It sends more requests I guess because it's not getting a 200 response.
But what am I doing wrong here?
EDIT: I checked through the shopify-cli and got this
pry(main)> ShopifyAPI::Webhook.all
=> []
So did Shopify create the Webhooks or not? I'm looking at two in the admin.
After I create them with from the CLI with
ShopifyAPI::Webhook.create({topic: 'products/update', address: 'https://my_url', format: 'json'})
I can see them with the 'Webhook.all' command, but I still get the same error as above.
Here's the issue:
Your Shopify App uses WebhookManager to register webhooks automatically. These webhooks are completely separate from your Store Admin notification webhooks.
Shopify App webhooks are signed with the app's secret. Whereas Store Admin notification webhooks use a different signing key, as you can see highlighted in yellow.
To fix this, delete the notification webhooks in your Store Admin. And rely fully on webhooks that your app sets up with the WebhookManager. Your app will register webhooks when you sign out, and sign back in with your app.
Hello @tolgapaksoy, thanks for your response here. One question though, how can we send test webhook events without the admin though?
User | Count |
---|---|
12 | |
12 | |
10 | |
7 | |
6 |