-
Notifications
You must be signed in to change notification settings - Fork 476
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
Documentation / Requirements for Private App Usage (v10) #911
Comments
Hey @MikeParkin we're looking into this! |
Hey @milakoeva thanks! One solution might be a method per app type, so a private app could do:
Just a thought, I'm sure there are lots of solutions! |
@mllemango This is very important. PLEASE update the docs (and necessary code) with clear instructions on how to use this gem with just a private app to make REST API calls. Many, many developers use it this way in a backend system with no browser/oauth system available. |
@mllemango Thanks for looking into this! I am running into the same issue, poorly documented on how to use the setup context and what is required... Just went from a project on version 9.5 something to 10+ and for the life of me I cannot get my private app to initialize properly |
Hey, after trial and error and scrounging through shopify's code, I found something that works. In some kind of initializer: ShopifyAPI::Context.setup(
# These values are required but not actually used for private apps
api_key: "DUMMY_VALUE",
host_name: "DUMMY_VALUE",
scope: "DUMMY_VALUE",
private_shop: ENV.fetch("SHOPIFY_STORE_DOMAIN"),
api_secret_key: ENV.fetch("SHOPIFY_ADMIN_API_ACCESS_TOKEN"), # Note that this is actually the admin token, not the api secret key
session_storage: ShopifyAPI::Auth::FileSessionStorage.new, # This is only to be used for testing, more information in session docs
is_embedded: false, # Set to true if you are building an embedded app
is_private: true, # Set to true if you are building a private app
api_version: "2022-01" # The vesion of the API you would like to use
) Then, later... session = ShopifyAPI::Utils::SessionUtils.load_current_session
client = ShopifyAPI::Clients::Graphql::Admin.new(session: session)
client.query(query: MY_QUERY) Tada! Hope this helps! |
Hey while looking into this could you also take a look at how to make the context setup work with multiple private apps in different stores e.g. one rails application that supports working with multiple private apps. Beforehand you were able to create a session on request basis but this doesn't work properly currently because you cannot specify the api version (except if you specify it in the path for REST API, unsure about GraphQL API). |
This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days. |
This shouldn’t be closed |
@mllemango Can you please update us here? |
Got here after receiving an email alert for deprecation of the 2022-01 API, and my first reflex was to update the gem. I discovered afterwards that the simple initialisation method for private apps used in v9 would no longer work, as the gem was completely reworked and the update process was not at all as straightforward as I tought, and finally discovered @bkroeker's hack. But I'm not a gambler and will stay as much as possible on the V9.5.1 gem as long as the doc is not clear regarding private apps handling. So unfortunately my solution for now, is just updating the env var SHOPIFY_API_VERSION to 2022-10 and in the gemfile : gem 'shopify_api', '~> 9.5.1' I don't know however for how long this will work. |
To add up on the solution provided by @bkroeker, I've been able to perform queries with this minimal setup: class Gateway
attr_reader :admin_api_access_token
attr_reader :store_domain
def initialize(admin_api_access_token:, store_domain:)
@admin_api_access_token = admin_api_access_token
@store_domain = store_domain
end
def query(query, variables)
graphql_client.query(
query: query,
variables: variables
)
end
private
def graphql_client
@graphql_client ||= ShopifyAPI::Clients::Graphql::Admin.new(session: session)
end
def session
@session ||= ShopifyAPI::Auth::Session.new(
shop: store_domain,
access_token: admin_api_access_token
)
end
end
gateway = Gateway.new(
store_domain: 'unicorn.myshopify.com',
admin_api_access_token: 'shpat_2a6....'
)
GET_PRODUCTS = <<~GQL
query getProducts($first: Int!) {
products(first: $first) {
edges {
node {
id
title
}
}
}
}
GQL
gateway.query(GET_PRODUCTS, first: 10) It's worth noting that I didn't find a way to set the |
I am experiencing the same challenge. @GesJeremie , Is there any way to use this method and use the built in resources i.e. Product.all, Order.all, etc? |
@iyerushalmi I've managed to get the built-in rest resources working: def get_shop
session = ShopifyAPI::Auth::Session.new(
shop: "shop.myshopify.com",
access_token: "XXX"
)
ShopifyAPI::Context.activate_session(session)
ShopifyAPI::Context.load_rest_resources(api_version: "2023-01")
ShopifyAPI::Shop.all.first
end |
This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days. |
This shouldn’t be closed |
This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days. |
Still shouldn’t be closed |
We were able to get Ruby API calls working with our private app using this config: shopify.rb (config/initializers)
Now to make an API call in Ruby:
|
@key88sf what versions of ruby, rails, and the gems are you using? what guide did you start with? when I use your code in my initializer, I get this error on starting the rails server:
|
@porterbayne Currently using: |
Thanks, I'll try those. I'm on Ruby 3.0.x and Rails 7. Did you use any particular setup guide? Is there a repo you're OK sharing? I spent a half day getting nowhere on this. :( |
I think I started with the code generated from this: https://github.com/Shopify/shopify_app Make sure you're using the latest |
This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days. |
Still shouldn’t be closed |
Still a considerable blocker for me. |
This issue is still a blocker for me. |
Same and so we're unable to build a necessary internal system and using spreadsheets instead. @ShayneP thank you for assigning it to yourself. Are there any updates? |
Any updates? |
@porterbayne for us this format works... ShopifyAPI::Context.setup( private_shop: ENV["SHOPIFY_DOMAIN"], #session_storage: ShopifyAPI::Auth::FileSessionStorage.new, # This is only to be used for testing, more information in session docs |
Thank you, I will try it soon! |
Hi folks 👋 I wanted to flag this documentation on how to make requests for private/merchant custom apps that was previously added. It seems like the one limitation here is that you cannot set the API Version without setting other required context information, which may not be relevant for merchant custom apps, and requires you to set it up with dummy information. I am going to create a issue to look into resolving this. I am going to close this issue. If there are other limitations you are facing please create a new issues for these so we are best able to track them, and they don't get lost in long comment threads. For reference here is the simple script using the above documentation to make API calls.
|
@lizkenyon Thanks! |
Issue summary
Actually writing this because of an issue I raised for the PHP Shopify API library.
Shopify/shopify-api-php#151
In summary, when using a private app only the Shop URL and store API token are required, yet Context::initialize is required to be called with lots of non-required values (the majority of which aren't required if you use the Rest client directly) which is a bit confusing when you're trying to use the library for the first time.
In the pre-10 version of this Ruby library there was a usage description for private apps that was very clear to understand:
https://github.com/Shopify/shopify_api/tree/v9#2a-private-apps
https://github.com/Shopify/shopify_api/tree/v9#6a-making-requests-to-the-graphql-api
In the main branch this has been changed to similar documentation to the PHP library:
https://github.com/Shopify/shopify_api#setup-shopify-context
My understanding of Ruby is limited, however from what I can see, although named parameters are supported in Ruby, it still appears that most of the settings are required:
https://github.com/Shopify/shopify_api/blob/main/lib/shopify_api/context.rb#L42
Does this Ruby API actually require session storage, scope etc when using a private app? (The PHP version doesn't need them, but they are still required - you have to pass in dud values). Just seems a bit odd/confusing that I have to "initialize a session" just so that a Rest/GraphQL library can then use them - when the only required values are the host name and store API token.
I'm guessing documentation isn't finished yet for this, but it's causing confusion on the PHP side so thought I'd ask here too!
Specifications
shopify_api
version:The text was updated successfully, but these errors were encountered: