Skip to content
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

Adds api version configuration example for custom app #1330

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading