I want to perform a job when an order is created in Shopify, but it seems as if nothing is listening to the webhook and I can't figure out why. I followed the documentation for the shopify_app gem but it is not working.
I ran
rails g shopify_app:add_webhook -t orders/create -a https://example.com/webhooks/orders_create
Initializer shopify_app.rb
ShopifyApp.configure do |config|
...
config.webhooks = [
{topic: 'orders/create', address: 'https://myappwebaddress_not_showing_on_stackoverflow/webhooks/orders_create', format: 'json'},
]
...
end
I am using the WebhooksController
module ShopifyApp
class WebhooksController < ApplicationController
include ShopifyApp::WebhookVerification
class ShopifyApp::MissingWebhookJobError < StandardError; end
def receive
params.try(:permit!)
job_args = {shop_domain: shop_domain, webhook: webhook_params.to_h}
webhook_job_klass.perform_later(job_args)
head :no_content
end
private
def webhook_params
params.except(:controller, :action, :type)
end
def webhook_job_klass
"#{webhook_type.classify}Job".safe_constantize or raise ShopifyApp::MissingWebhookJobError
end
def webhook_type
params[:type]
end
end
end
I know the webhook is created because I display it within the app view and it shows.
[#<ShopifyAPI::Webhook:0x007f183012d578 @attributes={"id"=>462377288, "address"=>"https://myappwebaddress_not_showing_on_stackoverflow/webhooks/orders_create", "topic"=>"orders/create", "created_at"=>"2016-11-29T20:29:24-08:00", "updated_at"=>"2016-11-29T20:29:24-08:00", "format"=>"json", "fields"=>[], "metafield_namespaces"=>[]}, @prefix_options={}, @persisted=true>]
When I create an order through Shopify, nothing happens in my app.
I should add, I am using sidekiq to process the job. Sidekiq is working because when I "install" the app in Shopify, it processes the job of creating the webhook.
What am I missing to process the webhook? Do I still need to create something in routes.rb? Nothing in the documentation says I need to. I tried creating a route post 'webhooks/orders_create' => 'webhooks#receive'
But, that didn't do anything.
What do I need to do?