Skip to content

Instantly share code, notes, and snippets.

@lancejohnson
Created August 23, 2023 16:52
Show Gist options
  • Save lancejohnson/6fbf0d26ea5802a4d7c6135e142dd166 to your computer and use it in GitHub Desktop.
Save lancejohnson/6fbf0d26ea5802a4d7c6135e142dd166 to your computer and use it in GitHub Desktop.
Shopify GraphQL query using Requests
# Instantiate the client with an endpoint.
endpoint="https://renovationreserve.myshopify.com/admin/api/2023-07/graphql.json"
# Provide a GraphQL query
query = """
query ProductsBySku($skuFilter: String!){
products(first: 1, query: $skuFilter) {
edges {
node {
id
title
priceRangeV2 {
maxVariantPrice {
amount
currencyCode
}
minVariantPrice {
amount
currencyCode
}
}
vendor
variants(first: 10) {
edges {
node {
availableForSale
id
inventoryItem {
unitCost {
amount
currencyCode
}
}
}
}
}
}
}
}
}
"""
skus = [
"HP21-Black",
"HP21-Black-SS"
]
# Prepare items for the request
variables = {"skuFilter": f"sku:{sku}"}
data = {
"query": query,
"variables": variables
}
headers = {
'Content-Type': 'application/json',
'X-Shopify-Access-Token': shopify_api_key
}
resp = requests.post(url=endpoint, json=data, headers=headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment