Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register webhook manually #1259

Closed
remy727 opened this issue Jan 4, 2024 · 6 comments
Closed

Register webhook manually #1259

remy727 opened this issue Jan 4, 2024 · 6 comments

Comments

@remy727
Copy link
Contributor

remy727 commented Jan 4, 2024

Issue summary

I want to register orders/fulfilled webhook for one of my public app customers.

shop = Shop.find_by(shopify_domain: "client-store.myshopify.com")
shop.with_shopify_session do
  ShopifyAPI::Webhooks::Registry.add_registration(
    topic: "orders/fulfilled",
    delivery_method: :http,
    handler: OrdersFulfilledJob,
    path: "https://myapp.com/api/custom_webhooks/orders_fulfilled"
  )
end
ShopifyAPI::Webhooks::Registry.register(topic: "orders/fulfilled", session: shop.session)

I was able to register the webhook and confirmed it was added.
But I am getting ShopifyAPI::Errors::NoWebhookHandler (No webhook handler found for topic: orders/fulfilled error when running the below code.

ShopifyAPI::Webhooks::Registry.process(ShopifyAPI::Webhooks::Request.new(raw_body: request.raw_post,
      headers: headers))
  • shopify_api version: 13.2.0
  • Ruby version: 3.2.1
  • Operating system: Linux/Heroku
ShopifyAPI::Errors::NoWebhookHandler (No webhook handler found for topic: orders/fulfilled 

Expected behavior

Handles orders/fulfilled webhook

Actual behavior

No webhook handler found for topic: orders/fulfilled

Steps to reproduce the problem

  1. Register webhook manually with the above code
  2. Fulfill the order in the Shopify Admin
@lizkenyon
Copy link
Contributor

Hi there 👋

Just a couple of things to double check here

  • Your handler is set up correctly. e.g. OrdersFulfilledJob extends ShopifyAPI::Webhooks::Handler Docs here
  • You are reloading the registry on server restart.

The webhooks you register with Shopify are saved in the Shopify platform, but the local ShopifyAPI::Webhooks::Registry needs to be reloaded whenever your server restarts.
Docs

@remy727
Copy link
Contributor Author

remy727 commented Jan 8, 2024

@lizkenyon, thank you for your reply.

  • I confirmed OrdersFulfilledJob extends ShopifyAPI::Webhooks::Handler
  • How can I reload ShopifyAPI::Webhooks::Registry? I just restarted dynos on Heroku before.

@lizkenyon
Copy link
Contributor

How can I reload ShopifyAPI::Webhooks::Registry?

In your apps boot up code you will need to have code that adds your handlers to your registry.

You can see an example in the ruby template that uses a helper from shopify_app gem.

@remy727
Copy link
Contributor Author

remy727 commented Jan 8, 2024

Aha got it. I am already using that ruby template.

@lizkenyon
Copy link
Contributor

👍 Hope that resolves that for you.

If you have any suggestions/a PR on how we could clarify this in the documentation I would love to hear it. Thanks! 😄

@weizheheng
Copy link

Hi @remy727, did you manage to figure it out? I am having the same issue:

  1. I have a base webhooks for every users and it's set in the config.webhooks in the shopify_app initializer
  2. Then I have a few webhooks I want to add for certain shops only, but after registering the specific webhook for a shop, the Registry is not "reloaded" I will assume:
  # Here the @registry is only the one I set in the `config.webhooks` not including the new registration 
  handler = @registry[request.topic]&.handler

  # This error is then raised
  unless handler
    raise Errors::NoWebhookHandler, "No webhook handler found for topic: #{request.topic}."
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants