Skip to content

Commit 86ced16

Browse files
committed
Adds shopify context setup for custom app rest calls
1 parent e3c4104 commit 86ced16

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

docs/usage/custom_apps.md

Lines changed: 11 additions & 5 deletions
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: false, # 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,12 +71,9 @@ 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-
# you can set the api version for your GraphQL client
74+
# you can set the api version for your GraphQL client to override the api version in ShopifyAPI::Context
6675
graphql_client = ShopifyAPI::Clients::Graphql::Admin.new(api_version: "2024-07")
6776

68-
# REST example
69-
ShopifyAPI::Context.load_rest_resources(api_version: "2024-07")
70-
7177
# 2. Use API client to make queries
7278
# Graphql
7379
query = <<~QUERY
@@ -87,7 +93,7 @@ def make_api_request
8793

8894
response = graphql_client.query(query: query)
8995

90-
# REST
96+
# Use REST resources to make authenticated API call
9197
product_count = ShopifyAPI::Product.count
9298

9399
...

0 commit comments

Comments
 (0)