Attempting to update from Ruby Shopify APi v9 to v10

Solved

Attempting to update from Ruby Shopify APi v9 to v10

wgbrown
Visitor
2 1 3

Hello, 

I am attempting to update a private app from shopify_api v9 to shopify_api v10 as I am unable to pull the schema for graphql 2022-04. The working code currently uses the schema for 2020-10 however I would like to be able to take advantage of the new data the new api version can provide me.

It appears the method for authentication is different based on the API's documentation. I have verified my private admin access is working through a curl command however my scripts are written in Ruby. 

I have added the the Shopify::Context.Setup as noted in the documentation and attempted connection however as admin access does not use Oauth this of course fails with the following error: 
ShopifyAPI::Errors::UnsupportedOauthError: Cannot perform OAuth for private apps.

Previous connection connections where made with code that looks like this: 

 

 

    _url = "https://#{api_key}:#{password}@#{shop_name}.myshopify.com"
    ShopifyAPI::Base.site = _url
    ShopifyAPI::Base.api_version = '2020-10'
    ShopifyAPI::GraphQL.initialize_clients
     = ShopifyAPI::GraphQL.client

 

 

I also found the following as the call to session in documentation: 

 

 

# load the current session with SessionUtils.load_current_session
session = ShopifyAPI::Utils::SessionUtils.load_current_session(auth_header: <auth-header>, cookies: <cookies>, is_online: <true|false>)

# initalize the client
client = ShopifyAPI::Clients::Graphql::Admin.new(session: session)

 

 

However, I do not know where to get the data needed for <auth-header> or <cookies> as clearly the session need to be loaded prior to setting up the client. 

Maybe I am missing this in the APi documentation but can someone give me some information as to how to set up the client connection through private admin app that does not require the Schema json (This is not a rails app so I am unable to use rake) that was used previously nor requiring Oauth configurations? 

Or if possible how can i get the schema file without rake? 

Accepted Solution (1)

wgbrown
Visitor
2 1 3

This is an accepted solution.

I wanted to updated for anyone who also has this issue. I fell into the answer: 

 

 

    session = ShopifyAPI::Auth::Session.new(
      shop: "#{shop_name}.myshopify.com",
      access_token: token_goes_here,
    )
    client = ShopifyAPI::Clients::Graphql::Admin.new(
      session: session
    )

 

 

However at this point looking at the gems git I am unable to determine how to set which api version is being used. 

Its showing the most current in the response which is good for now but what if i want to hold that version in the future? the Admin.New call does not accept api_version: option.

View solution in original post

Replies 3 (3)

wgbrown
Visitor
2 1 3

This is an accepted solution.

I wanted to updated for anyone who also has this issue. I fell into the answer: 

 

 

    session = ShopifyAPI::Auth::Session.new(
      shop: "#{shop_name}.myshopify.com",
      access_token: token_goes_here,
    )
    client = ShopifyAPI::Clients::Graphql::Admin.new(
      session: session
    )

 

 

However at this point looking at the gems git I am unable to determine how to set which api version is being used. 

Its showing the most current in the response which is good for now but what if i want to hold that version in the future? the Admin.New call does not accept api_version: option.

ronald_g
Explorer
71 2 9

You can also try

 

 

ShopifyAPI::Auth::Session.temp(shop: shop_model.shopify_domain, access_token:shop_model.shopify_token) do |session|
  client = ShopifyAPI::Clients::Graphql::Admin.new(session: session)
  client.query(query: query, variables: variables)
end

 

 

Todd_Trimakas
Shopify Partner
142 0 28

How nice of a world would it be if this was actually documented somewhere?

ByteStand - Amazon to Shopify in one click