From e3c4104c9464a11434cbd179767c108ae8b9a1bc Mon Sep 17 00:00:00 2001 From: Si Le <10522258+sle-c@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:17:20 -0400 Subject: [PATCH 1/3] Adds api version configuration example for custom app - Adds graphql client example with api version - Adds REST api version setting example --- docs/usage/custom_apps.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/usage/custom_apps.md b/docs/usage/custom_apps.md index b09a03beb..d7ca05685 100644 --- a/docs/usage/custom_apps.md +++ b/docs/usage/custom_apps.md @@ -62,9 +62,34 @@ end def make_api_request # 1. Create API client without session information # The graphql_client will use `ShopifyAPI::Context.active_session` when making API calls - graphql_client = ShopifyAPI::Clients::Graphql::Admin.new + # you can set the api version for your GraphQL client + graphql_client = ShopifyAPI::Clients::Graphql::Admin.new(api_version: "2024-07") + + # REST example + ShopifyAPI::Context.load_rest_resources(api_version: "2024-07") # 2. Use API client to make queries + # Graphql + query = <<~QUERY + { + products(first: 10) { + edges { + cursor + node { + id + title + onlineStoreUrl + } + } + } + } + QUERY + + response = graphql_client.query(query: query) + + # REST + product_count = ShopifyAPI::Product.count + ... end From 86ced161e9977f4ec94cc9aaa79b97b20bb09bcb Mon Sep 17 00:00:00 2001 From: Si Le Date: Wed, 17 Jul 2024 12:02:03 -0400 Subject: [PATCH 2/3] Adds shopify context setup for custom app rest calls --- docs/usage/custom_apps.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/usage/custom_apps.md b/docs/usage/custom_apps.md index d7ca05685..5f12849f3 100644 --- a/docs/usage/custom_apps.md +++ b/docs/usage/custom_apps.md @@ -53,6 +53,15 @@ def configure_app access_token: "the_token_for_your_custom_app_found_in_admin" ) + ShopifyAPI::Context.setup( + api_key: "", + api_secret_key: "", + scope: "read_orders,read_products,etc", + is_embedded: true, # Set to true if you are building an embedded app + api_version: "2024-01", # The version of the API you would like to use + is_private: false, # Set to true if you have an existing private app + ) + # Activate session to be used in all API calls # session must be type `ShopifyAPI::Auth::Session` ShopifyAPI::Context.activate_session(session) @@ -62,12 +71,9 @@ end def make_api_request # 1. Create API client without session information # The graphql_client will use `ShopifyAPI::Context.active_session` when making API calls - # you can set the api version for your GraphQL client + # you can set the api version for your GraphQL client to override the api version in ShopifyAPI::Context graphql_client = ShopifyAPI::Clients::Graphql::Admin.new(api_version: "2024-07") - # REST example - ShopifyAPI::Context.load_rest_resources(api_version: "2024-07") - # 2. Use API client to make queries # Graphql query = <<~QUERY @@ -87,7 +93,7 @@ def make_api_request response = graphql_client.query(query: query) - # REST + # Use REST resources to make authenticated API call product_count = ShopifyAPI::Product.count ... From 3e2fb09c3254790e74c1b928a13459c6e7f6f2fe Mon Sep 17 00:00:00 2001 From: Si Le Date: Wed, 17 Jul 2024 12:21:26 -0400 Subject: [PATCH 3/3] Set is_private to true because of custom app --- docs/usage/custom_apps.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage/custom_apps.md b/docs/usage/custom_apps.md index 5f12849f3..133e7ac37 100644 --- a/docs/usage/custom_apps.md +++ b/docs/usage/custom_apps.md @@ -59,7 +59,7 @@ def configure_app scope: "read_orders,read_products,etc", is_embedded: true, # Set to true if you are building an embedded app api_version: "2024-01", # The version of the API you would like to use - is_private: false, # Set to true if you have an existing private app + is_private: true, # Set to true if you have an existing private app ) # Activate session to be used in all API calls