3
votes

I'm trying to setup a basic shopify webhook app with order/create in Rails.

I have followed the instructions in the support api for webhooks and deployed the Sync_App_Demo example provided there but cannot get to authorise log in authorize step. It brings up the 'We're sorry something went wrong' page - myapp/login/authenticate

I'm new to webhooks and have looked all over SO and googled but had no joy working out the basic set up for the webhook connection. I placed the shopify app api key and secret in the based on the shopify_app gem setup which is created but not sure if this is correct.

Also once I do get connnected via a webhook controller where abouts do point (eg. what url /order.xml in the order notifcations panel of my test shop) the webhook order/create?

Any help would be much appreciated.

Here is the link to the shopify sync app demo:

https://github.com/Shopify/sync_app_demo

http://wiki.shopify.com/WebHook#Rails

2
Could you edit your question and post a link to said tutorial / demo app?Thomas Klemm
Hi Thomas, I've edited the original question with the said demo and still not getting anywhere with this I have found another SO question which displays some information about shopify webhooks but can't seem to implement it into my basic app. Here is the link: stackoverflow.com/questions/11435428/…RichNomadic

2 Answers

7
votes

Stumbled upon your question when searching for how to do this myself. Given that it's been more than a few years since you posted this here, hopefully you've already found the answer. If you haven't, here's what we did:

In both cases, you'll have to know your Shopify API key, password, and store name.

1) Using Shopify's shopify_api gem:

new_webhook = ShopifyAPI::Webhook.new({
   topic: "orders/create",
   address: "http://www.example.com/webhook", # substitute url with your endpoint
   format: "json"
})

new_webhook.save

2) Using terminal:

curl -X POST -H 'Content-Type: application/json' 'https://shopify_api_key:shopify_api_password@store_name.myshopify.com/admin/webhooks.json' -d '{"webhooks": {"topic": "orders\/create", "address": "http:\/\/www.example.com\/webhook", "format": "json"}}' 

You so you'll need to add in your own shopify_api_key, shopify_api_password, store_name, and address endpoint that you want to receive the published events.

Other useful things:

Ultrahook - for receiving webhooks on locally run server (eg. when using rails s)

RequestBin - for seeing webhook responses raw body and headers

0
votes

For new people getting started with Shopify App development with Ruby on Rails, I strongly suggest using the shopify_app gem that includes the shopify_api gem.

To register a webhook, you can run the add_webhook generator or add a line manually in the shopify_app.rb initializer:

config.webhooks = [
  {topic: 'app/uninstalled', address: 'https://myapp.url/webhooks/app_uninstalled', format: 'json'},
  {topic: 'orders/create', address: 'https://myapp.url/webhooks/orders_create', format: 'json'},
]

With this setup, your app will register the webhooks on application install.