postman Shopify API订单数据

sg24os4d  于 2022-12-23  发布在  Postman
关注(0)|答案(1)|浏览(233)

我想获取任何给定范围内的Shopify订单数据,但无法实现
代码如下所示:
我已经使用 Postman 呼叫get请求

import requests 
import pandas as pd 

url = "https://{apikey}:{passcode_with_token}@{store_name}/admin/api/2022-10/orders.json?status=any"

payload={}
headers = {
  'Authorization': 'Bearer token_value'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)
brtdzjyr

brtdzjyr1#

我建议您使用https://github.com/Shopify/shopify_python_api
此外,要检索某个时间段内的订单,我建议您使用graphql而不是REST api。
给你们举个例子

{
    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']

请记住,您必须处理结果中的分页(这与REST API相同),并且要检索超过120天的订单(我可能是错的,但情况类似),您需要特定的权限。

相关问题