Home > Software engineering >  How to view the X-Shopify-Shop-Api-Call-Limit
How to view the X-Shopify-Shop-Api-Call-Limit

Time:01-19

I want to view this specific header: X_SHOPIFY_SHOP_API_CALL_LIMIT

When I do this:

  CreateShopifyClientService.call(shop)
  begin
    response = ShopifyAPI::InventoryLevel.find(:all, params: { inventory_item_ids: product.inventory_item_id})
    byebug
  rescue Exception => e
    byebug
  end

I've tried just about everything I can think of, including looking thru the tests on the gem and cannot find the mysterious header.

Here are some of my futile attempts:

    (byebug) ap response.header
*** NoMethodError Exception: undefined method "header' for #<ShopifyAPI::PaginatedCollection:0x000055b39213c9c8>

(byebug) ap response.headers
*** NoMethodError Exception: undefined method "headers' for #<ShopifyAPI::PaginatedCollection:0x000055b39213c9c8>

CodePudding user response:

I just did this in my terminal and it worked a peach...

shop = Shop.first
session = ShopifyAPI::Auth::Session.new(
 shop: shop.shopify_domain,
 access_token: shop.shopify_token
)
client = ShopifyAPI::Clients::Rest::Admin.new(
 session: session
)

response = client.get(path: "products")
p response.headers["x-shopify-shop-api-call-limit"]
["1/40"]
=> ["1/40"]

So it is not too terribly hard to access the response headers. I see you're getting the response of the API call and not the HTTP response itself, so it seems you need to approach it differently for those old API calls. Maybe try updating to the more modern API and see if that helps you out.

  • Related