Created
August 23, 2023 16:52
-
-
Save lancejohnson/6fbf0d26ea5802a4d7c6135e142dd166 to your computer and use it in GitHub Desktop.
Shopify GraphQL query using Requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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