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

Resources not loading when using session based auth #1263

Closed
agbaber opened this issue Jan 11, 2024 · 5 comments
Closed

Resources not loading when using session based auth #1263

agbaber opened this issue Jan 11, 2024 · 5 comments
Assignees

Comments

@agbaber
Copy link

agbaber commented Jan 11, 2024

Issue summary

When using session-based auth, admin API resources are not being autoloaded correctly. Note that this is the same issue as this one, which was auto-closed.

  • shopify_api version: 13.3.1
  • Ruby version: 3.2.2
  • Operating system: Mac OS Ventura 13.6.3
require 'shopify_api'
=> true

session = ShopifyAPI::Auth::Session.new(
  shop: "myshopname.myshopify.com"
  access_token: "token_for_my_custom_app_found_in_admin"
)
=> 
#<ShopifyAPI::Auth::Session:0x000000012611da10
...

ShopifyAPI::Product.all(session: session)

(irb):7:in `<main>': uninitialized constant ShopifyAPI::Product (NameError)
Did you mean?  Proc
	from /Users/andrewb/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
	from /Users/andrewb/.rbenv/versions/3.2.2/bin/irb:25:in `load'
	from /Users/andrewb/.rbenv/versions/3.2.2/bin/irb:25:in `<main>'

Expected behavior

The latest-versioned Resources should be autoloaded when an explicit version is not specified.

Actual behavior

The gem does not load the Resources and returns an uninitialized constant error.

Steps to reproduce the problem

  1. require the gem (require 'shopify_api')
  2. make a session with ShopifyAPI::Auth::Session.new
  3. attempt to use that session to access a resource (ShopifyAPI::Product.all(session: session))
@sshaw
Copy link

sshaw commented Jan 12, 2024

Just had the same problem myself with 13.3.1 under Ruby 3.1 and 2.7. So many docs, but not a single way showing you how to require. Upon further investigation, it looks like this is intentional as they're using Zeitwerk!

My my my what in tarnation have they done to this library! REST API call now require native library compilation and installing sorbet-runtime 😱🤯👎

@sshaw
Copy link

sshaw commented Jan 12, 2024

@agbaber here is what you must do, in some form. This case assumes you're calling from an app but hopefully this will get you somewhere:

ShopifyAPI::Context.setup(
  :api_key => a,
  :api_secret_key => b,
  :api_version => "2023-07",
  :is_private => false,
  :scope => "your scopes",
  :is_embedded => false
)

ShopifyAPI::Context.activate_session(
  ShopifyAPI::Auth::Session.new(
    :shop => shopify_domain,
    :access_token => shopify_token,
  )
)

ShopifyAPI::Product.find(id: id)

zOMG

@agbaber
Copy link
Author

agbaber commented Jan 12, 2024

Thanks @sshaw!

Upon further investigation, it looks like this is intentional as they're using Zeitwerk!

Yeah, it does seem intentional (and predicated on choosing an api_version in the Context.setup), though you'd think it would auto-default to latest.

Your suggestion does work, but at that point, aren't you using api_key/secret auth instead of access_token? Seems like there's no point to the access_token then.

Edit: Hmm, no I guess you do need both. Obnoxious that it's not obvious in the docs.

Hilariously, all the doc examples use access_token and are currently failing due to this issue.

@lizkenyon
Copy link
Contributor

Hi folks 👋

Thank you for the feedback, I appreciate it, I am going to bring this up with the team. I definitely understand the confusion.
I am glad to hear that you have been able to work around this, and get this working.

@sle-c sle-c self-assigned this Jan 22, 2024
@sle-c
Copy link
Contributor

sle-c commented Feb 8, 2024

hey folks, this results from a breaking change in v10 of this gem https://github.com/Shopify/shopify-api-ruby/blob/main/BREAKING_CHANGES_FOR_V10.md

We're updating the doc to reflect that.

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

4 participants