401 Unauthorized Error

wasim-akhtar
New Member
5 0 0

Hello , 

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?

Replies 5 (5)

Gregarican
Shopify Partner
1033 86 285

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

wasim-akhtar
New Member
5 0 0

@Gregarican 

Thanks for replying. But I still got the same 401 Unauthorized access for the shops. 

Gregarican
Shopify Partner
1033 86 285

I'd suggest posting one of the failed X-Request-ID's, which are passed back in the response header. A Shopify support staffer can cross-reference the request ID to see what's going on. 

wasim-akhtar
New Member
5 0 0

@Gregarican 

Here is the X-Request-ID:  b2a9ce97-93ae-4a0e-80c9-e8eb3991172d and  X-ShopID : 1609924677

AndyPicamaze
Explorer
41 1 15

Hi,

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?

https://apps.shopify.com/picamaze
Animated watermarks for product images and ads