I wrote a simple script to find out shops having a webhook registered. But it gives 401 Unauthorized error for a lot of shops even though the app is installed and functioning on those shops. It does give correct count for some of the shops. Here is the code
Shop.all.each do |shop| puts shop.shopify_domain begin shop.with_shopify_session do pp "count: " +(ShopifyAPI::Webhook.all.nil? ? "0": ShopifyAPI::Webhook.all.count.to_s) end rescue ActiveResource::UnauthorizedAccess => e puts e.message end end
What could be the reason for it and how can I debug it?
Have you verified access scopes allowed for each shop you are hitting? If some return results while others don't perhaps that's the issue? See here --> https://shopify.dev/docs/admin-api/rest/reference/access/accessscope
Is this script executed when the shop owners are offline (logged out)? If you use online access mode the access token expire with the user's sessions and then you get the Unauthorized Error. Can you show me the exact error message?