简体   繁体   English

Shopify API 订单数据

[英]Shopify API orders data

I want to fetch Shopify orders data in any given range but not able to do so我想获取任何给定范围内的 Shopify 订单数据,但无法这样做

The code is written below:代码如下:

I have used postman to call the get requests我用邮递员来调用获取请求

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)

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.此外,要检索某个时间段之间的订单,我建议您使用 graphql 而不是 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.请记住,您必须处理结果中的分页(这与 REST api 相同)并检索超过 120 天的订单(我可能是错的但类似)您需要特定的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM