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

recreate_webhooks! fails to recreate webhooks as it tries to create mandatory webhooks using the API #1659

Closed
sagar-ranglani opened this issue Feb 28, 2023 · 4 comments

Comments

@sagar-ranglani
Copy link

Issue summary

Can't use recreate_webhooks! as it tries to create mandatory webhooks using API and I guess that's now allowed!

  • shopify_api version: 12.4.0
  • shopify_app version: 21.4.0
  • Ruby version: 3.0.2
  • Operating system: Mac (Trying this in dev)
gems/shopify_api-12.4.0/lib/shopify_api/webhooks/registry.rb:154:in `get_webhook_id': Failed to fetch webhook from Shopify: Argument 'topics' on Field 'webhookSubscriptions' has an invalid value (SHOP_REDACT). Expected type '[WebhookSubscriptionTopic!]'. (ShopifyAPI::Errors::WebhookRegistrationError)

Expected behavior

It should recreate all the webhooks! (I guess, by trying to recreate only the non-mandatory ones)

Actual behavior

It fails with an error

Steps to reproduce the problem

  1. Try the following in the Rails console
irb> ShopifyApp.configuration.has_webhooks?
=> true
irb> ShopifyApp.configuration.webhooks
=>
[{:topic=>"app/uninstalled", :address=>"api/webhooks/app_uninstalled"},
 {:topic=>"orders/fulfilled", :address=>"api/webhooks/orders_fulfilled"},
 {:topic=>"bulk_operations/finish", :address=>"api/webhooks/bulk_operations_finish"},
 {:topic=>"orders/create", :address=>"api/webhooks/orders_create"},
 {:topic=>"app_subscriptions/update", :address=>"api/webhooks/app_subscriptions_update"},
 {:topic=>"shop/redact", :address=>"api/webhooks/shop_redact"},
 {:topic=>"customers/redact", :address=>"api/webhooks/customers_redact"},
 {:topic=>"customers/data_request", :address=>"api/webhooks/customers_data_request"}]

irb> shop = Shop.find_by(shopify_domain: 'xxx.myshopify.com')
=>
#<Shop:0x000000010b53bec8
irb> session = ShopifyAPI::Auth::Session.new(shop: shop.shopify_domain, access_token
: shop.shopify_token)
=>
#<ShopifyAPI::Auth::Session:0x0000000109598080
...
irb> ShopifyApp::WebhooksManager.recreate_webhooks!(session: session)
/Users/xxx/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/shopify_api-12.4.0/lib/shopify_api/webhooks/registry.rb:154:in `get_webhook_id': Failed to fetch webhook from Shopify: Argument 'topics' on Field 'webhookSubscriptions' has an invalid value (SHOP_REDACT). Expected type '[WebhookSubscriptionTopic!]'. (ShopifyAPI::Errors::WebhookRegistrationError)

@sagar-ranglani
Copy link
Author

@awd Could you please help me understand what could a simpler workaround here?

@m11o
Copy link
Contributor

m11o commented Mar 9, 2023

I have the same issue.

The documentation mentions the following.

You don't create webhook subscriptions to mandatory webhooks. Instead, you configure mandatory webhooks in your Partner Dashboard as part of your app setup.

So, How about mandatory webhooks should be removed from shopify_app generators in order to avoid confusion like us?

@m11o
Copy link
Contributor

m11o commented Mar 16, 2023

So, How about mandatory webhooks should be removed from shopify_app generators in order to avoid confusion like us?

It was wrong.
Mandatory webhook configures made by shopify_app initial generator are necessary when receiving these webhooks. So, we need to modify ShopifyAPI::Webhooks::Registry#register.

@nelsonwittwer
Copy link
Contributor

Should be fixed with this app gem PR

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