python - Shopify API orders data
Solution:
I suggest you to use this library https://github.com/Shopify/shopify_python_api (https://github.com/Shopify/shopify_python_api)
Furthermore, to retrieve orders between a certain period I suggest you to use graphql instead of the REST api.
To give you an example
{
orders(query:"created_at:>='2022-01-01T00:00:00BST' AND created_at:<='2022-12-31T23:59:59BST')", sortKey: CREATED_AT, reverse: true, first: 20) {
pageInfo {
hasNextPage
}
edges {
cursor
node {
createdAt
name
lineItems(first: 20) {
pageInfo {
hasNextPage
}
edges {
cursor
node {
variant {
title
inventoryQuantity
}
sku
title
quantity
}
}
}
}
}
}
}
shopify.Session.setup(api_key=client_id, secret=client_secret)
if password: # depending if you have a password (private app) or access token (custom/public app)
shopify_session = shopify.Session(store, api_version, password)
else:
shopify_session = shopify.Session(store, version=api_version, token=access_token)
shopify.ShopifyResource.activate_session(shopify_session)
def retrieve_orders():
with open('query.graphql', 'r') as fp:
query = fp.read()
result = json.loads(shopify.GraphQL().execute(query))
# ...
return resutl['edges']
Keep in mind that you have to handle pagination in the result (that would be the same with the REST api) and to retrieve orders older than 120 days (I can be wrong but is something similar) you need a specific permission.
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.