DEV Community

sugiarto
sugiarto

Posted on

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 http 3000
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
Shop.first.recreate_webhooks!
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay