簡體   English   中英

Shopify API 訂單數據

[英]Shopify API orders data

我想獲取任何給定范圍內的 Shopify 訂單數據,但無法這樣做

代碼如下:

我用郵遞員來調用獲取請求

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)

我建議你使用這個庫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 天的訂單(我可能是錯的但類似)您需要特定的權限。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM