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

Conversation

sle-c
Copy link
Contributor

@sle-c sle-c commented Jul 17, 2024

Description

Fixes #1329

  • Adds graphql client example with api version
  • Adds REST api version setting example

How has this been tested?

Script for graphql admin client with api version

require "shopify_api"

access_token = "shpat"
shop = "test.myshopify.com"

# Make the GraphQL query string
query = <<~QUERY
  {
    products(first: 10) {
      edges {
        cursor
        node {
          id
          title
          onlineStoreUrl
        }
      }
    }
  }
QUERY

session = ShopifyAPI::Auth::Session.new(
  shop: shop,
  access_token:
)

graphql_client = ShopifyAPI::Clients::Graphql::Admin.new(session: session, api_version: "unstable")
response = graphql_client.query(query: query)

puts response.body['data']

Script for REST

require "shopify_api"

access_token = "shpat"
shop = "test.myshopify.com"
session = ShopifyAPI::Auth::Session.new(
  shop: shop,
  access_token:
)
# use admin rest client to specify api version
rest_client = ShopifyAPI::Clients::Rest::Admin.new(session: session, api_version: "2024-01")
response = rest_client.get(path: "products")
p response

# use ShopifyApi::Context to specify api version
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: false, # Set to true if you have an existing private app
)
products = ShopifyAPI::Product.find_all
p products

Checklist:

  • My commit message follow the pattern described in here
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have updated the project documentation.
  • I have added a changelog line.

sle-c and others added 2 commits July 16, 2024 17:17
- Adds graphql client example with api version
- Adds REST api version setting example
@sle-c sle-c marked this pull request as ready for review July 17, 2024 16:02
@sle-c sle-c requested a review from a team as a code owner July 17, 2024 16:02
Copy link
Contributor

@lizkenyon lizkenyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these improvements! 🌟

@sle-c sle-c merged commit 6a74e1e into main Jul 17, 2024
9 checks passed
@sle-c sle-c deleted the sle-c/custom-app-api-version branch July 17, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow setting API_VERSION without initializing context for merchant custom apps
2 participants