Sylar Sylar - 1 year ago 90
Ruby Question

Use Rake to create webhooks in Shopify

Currently, if I add/remove a webhook from my application, for it to reflect in shopify app, the user has to reinstall the app. I need a way to avoid that so I thought I'd use rake.

For this I'm using the Rails ShopifyAPP. My app uses Rails 5.



config.after_initialize do



namespace :shopifyapp do
desc "create webhooks in shopify"
task :shopify_webhooks do
ShopifyApp.configure do |config|
config.webhooks = [
{topic: 'carts/update', address: 'https://some-external-address', format: 'json'},
puts "works" # outputs when server restarts

My 6th sense tells me something is not right with the rake file. Am I missing something? What's the issue? Webhooks are not creating.

If I add a new webhook in
, it will work only if the app is reinstalled.

Answer Source

Since you have a valid authentication token to the Shop, in your rake task just connect to the Shop, and use the API to create the webhook. It is very easy to do.

ShopifyAPI::Webhook.create(topic: 'orders/paid', address: 'https:foo', format: 'json')

I think that is more inline with how to use rake than to try and mimic Rails inside a rake task.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download