Skip to content

Commit 6a74e1e

Browse files
authored
Merge pull request #1330 from Shopify/sle-c/custom-app-api-version
Adds api version configuration example for custom app
2 parents c029d8a + 3e2fb09 commit 6a74e1e

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

docs/usage/custom_apps.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ def configure_app
5353
access_token: "the_token_for_your_custom_app_found_in_admin"
5454
)
5555

56+
ShopifyAPI::Context.setup(
57+
api_key: "<api-key>",
58+
api_secret_key: "<api-secret-key>",
59+
scope: "read_orders,read_products,etc",
60+
is_embedded: true, # Set to true if you are building an embedded app
61+
api_version: "2024-01", # The version of the API you would like to use
62+
is_private: true, # Set to true if you have an existing private app
63+
)
64+
5665
# Activate session to be used in all API calls
5766
# session must be type `ShopifyAPI::Auth::Session`
5867
ShopifyAPI::Context.activate_session(session)
@@ -62,9 +71,31 @@ end
6271
def make_api_request
6372
# 1. Create API client without session information
6473
# The graphql_client will use `ShopifyAPI::Context.active_session` when making API calls
65-
graphql_client = ShopifyAPI::Clients::Graphql::Admin.new
74+
# you can set the api version for your GraphQL client to override the api version in ShopifyAPI::Context
75+
graphql_client = ShopifyAPI::Clients::Graphql::Admin.new(api_version: "2024-07")
6676

6777
# 2. Use API client to make queries
78+
# Graphql
79+
query = <<~QUERY
80+
{
81+
products(first: 10) {
82+
edges {
83+
cursor
84+
node {
85+
id
86+
title
87+
onlineStoreUrl
88+
}
89+
}
90+
}
91+
}
92+
QUERY
93+
94+
response = graphql_client.query(query: query)
95+
96+
# Use REST resources to make authenticated API call
97+
product_count = ShopifyAPI::Product.count
98+
6899
...
69100
end
70101

0 commit comments

Comments
 (0)