Skip to content

Commit

Permalink
Merge pull request #1330 from Shopify/sle-c/custom-app-api-version
Browse files Browse the repository at this point in the history
Adds api version configuration example for custom app
  • Loading branch information
sle-c committed Jul 17, 2024
2 parents c029d8a + 3e2fb09 commit 6a74e1e
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion docs/usage/custom_apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ def configure_app
access_token: "the_token_for_your_custom_app_found_in_admin"
)

ShopifyAPI::Context.setup(
api_key: "<api-key>",
api_secret_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: true, # 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)
Expand All @@ -62,9 +71,31 @@ 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 to override the api version in ShopifyAPI::Context
graphql_client = ShopifyAPI::Clients::Graphql::Admin.new(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)

# Use REST resources to make authenticated API call
product_count = ShopifyAPI::Product.count

...
end

Expand Down

0 comments on commit 6a74e1e

Please sign in to comment.