Shopify / shopify_app

A Rails Engine for building Shopify Apps
MIT License
1.74k stars 685 forks source link

What changed in App and API calls? #1785

Closed resistorsoftware closed 5 months ago

resistorsoftware commented 5 months ago

Shopify App Version: 21.6.0

drop into a rails console, where we have an installed shop with full tokens.

shop = Shop.first
shop.with_shopify_session do
  ShopifyAPI::Product.count
end
==> NameError: uninitialized constant ShopifyAPI::Product

So a quick call on ShopifyAPI.constants shows a super small subset of the 87 I might get with other App installs. This tells me when I am dropping into Rails console, it is somehow not loading the Shopify API correctly? Huh? How is that a thing?

So this pattern has worked and continues to work in all my old projects, but in this new one, something changed and now the Resource style is pooched? I am a little confused. As an interesting contrast, the long-winded approach does work, proving the console is loading the API module somewhat, just not all the resources.

 shop.with_shopify_session do |session|
  client = ShopifyAPI::Clients::Rest::Admin.new(session: session)
  client.get(path: "webhooks")
end
=> #<ShopifyAPI::Clients::HttpResponse:0x0000000111537bd8
BaggioGiacomo commented 3 weeks ago

You just need to load the rest resources before using them:

shop.with_shopify_session do
  ShopifyAPI::Context.load_rest_resources(api_version: "2024-04")
  ShopifyAPI::Product.count
end