Recreate shopify webhooks

When developing custom Shopify apps, I usually use ngrok as a reverse proxy for webhooks integration. Since I always use a free service plan from Ngrok, then the URL address always changes. Here is the sample generated Ngrok URL when running

ngrok h…


This content originally appeared on DEV Community and was authored by sugiarto

When developing custom Shopify apps, I usually use ngrok as a reverse proxy for webhooks integration. Since I always use a free service plan from Ngrok, then the URL address always changes. Here is the sample generated Ngrok URL when running

ngrok http 3000

Generated endpoint
https://73d3-2001-448a-3032-c93e-bc56-f800-e58d-8a98.ngrok-free.app

When we hit ctrl+c and rerun the command, we will get a different new URL.

So what I did was just change the .env file of my Rails project, go to console, and recreate Shopify webhooks.

bundle exec rails c
Shop.first.recreate_webhooks!

And here is the code for recreate_webhooks!

# app/models/shop.rb

  def recreate_webhooks!
    ShopifyAPI::Webhook.all.each do |webhook|
      webhook.destroy
    end

    ShopifyApp.configuration.webhooks.each do |item|
      webhook = ShopifyAPI::Webhook.new(item)
      if webhook.save
        puts "webhook #{item} created."
      else
        puts "webhook #{item} failed."
      end
    end
  end

So every time you need to regenerate webhooks, you can just run this method from rails console.


This content originally appeared on DEV Community and was authored by sugiarto


Print Share Comment Cite Upload Translate Updates
APA

sugiarto | Sciencx (2024-09-10T23:25:44+00:00) Recreate shopify webhooks. Retrieved from https://www.scien.cx/2024/09/10/recreate-shopify-webhooks/

MLA
" » Recreate shopify webhooks." sugiarto | Sciencx - Tuesday September 10, 2024, https://www.scien.cx/2024/09/10/recreate-shopify-webhooks/
HARVARD
sugiarto | Sciencx Tuesday September 10, 2024 » Recreate shopify webhooks., viewed ,<https://www.scien.cx/2024/09/10/recreate-shopify-webhooks/>
VANCOUVER
sugiarto | Sciencx - » Recreate shopify webhooks. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/10/recreate-shopify-webhooks/
CHICAGO
" » Recreate shopify webhooks." sugiarto | Sciencx - Accessed . https://www.scien.cx/2024/09/10/recreate-shopify-webhooks/
IEEE
" » Recreate shopify webhooks." sugiarto | Sciencx [Online]. Available: https://www.scien.cx/2024/09/10/recreate-shopify-webhooks/. [Accessed: ]
rf:citation
» Recreate shopify webhooks | sugiarto | Sciencx | https://www.scien.cx/2024/09/10/recreate-shopify-webhooks/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.