取得清單 — 訂單
讀取「訂單」的資料。結果取決於此操作的參數。
GET/api/v1/orders
- 身份驗證
Bearer- 最低方案
- BASIC
- 所需權限
orders.order:read
程式碼範例
請求示例
cURL
: "${SHOPENTLY_SHOP_URL:?}"
curl --disable --globoff --fail-with-body --silent --show-error \
--proto '=https' --connect-timeout 5 --max-time 30 \
--request GET \
--header "Authorization: Bearer ${SHOPENTLY_ACCESS_TOKEN:?}" \
--url "${SHOPENTLY_SHOP_URL%/}"'/api/v1/orders?limit=20'
PHP
<?php
declare(strict_types=1);
$baseUrl = rtrim(getenv('SHOPENTLY_SHOP_URL') ?: '', '/');
$origin = parse_url($baseUrl);
if (!$origin || ($origin['scheme'] ?? '') !== 'https' || empty($origin['host']) ||
isset($origin['user'], $origin['pass']) || isset($origin['user']) || isset($origin['path']) ||
isset($origin['query']) || isset($origin['fragment'])) {
throw new RuntimeException('SHOPENTLY_SHOP_URL must be an HTTPS origin');
}
$credential = getenv('SHOPENTLY_ACCESS_TOKEN') ?: '';
if ($credential === '' || strpbrk($credential, "\r\n") !== false) {
throw new RuntimeException('Invalid credential');
}
$headers = [];
$headers[] = 'Authorization: Bearer ' . $credential;
$responseHeaders = [];
$handle = curl_init($baseUrl . '/api/v1/orders?limit=20');
curl_setopt_array($handle, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 30,
CURLOPT_HEADERFUNCTION => static function ($handle, string $line) use (&$responseHeaders): int {
if (str_contains($line, ':')) {
[$name, $value] = explode(':', $line, 2);
$responseHeaders[strtolower(trim($name))] = trim($value);
}
return strlen($line);
},
]);
$raw = curl_exec($handle);
$status = curl_getinfo($handle, CURLINFO_RESPONSE_CODE);
$error = curl_error($handle);
curl_close($handle);
if ($raw === false) {
throw new RuntimeException('Transport error: ' . $error);
}
if ($status < 200 || $status >= 300) {
throw new RuntimeException('HTTP ' . $status . '; request_id=' .
($responseHeaders['x-request-id'] ?? '') . '; retry_after=' . ($responseHeaders['retry-after'] ?? ''));
}
$result = $raw === '' ? null : json_decode($raw, true, 512, JSON_THROW_ON_ERROR | JSON_BIGINT_AS_STRING);
echo json_encode($result, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), PHP_EOL;
Python
from contextlib import ExitStack
import json
import os
from urllib.parse import urlsplit
import requests # python -m pip install requests
base_url = os.environ["SHOPENTLY_SHOP_URL"].rstrip("/")
origin = urlsplit(base_url)
if origin.scheme != "https" or not origin.hostname or origin.username or origin.password or origin.path or origin.query or origin.fragment:
raise ValueError("SHOPENTLY_SHOP_URL must be an HTTPS origin")
credential = os.environ['SHOPENTLY_ACCESS_TOKEN']
if not credential or "\r" in credential or "\n" in credential:
raise ValueError("Invalid credential")
headers = {}
headers["Authorization"] = 'Bearer' + " " + credential
body = None
if body is not None:
headers["Content-Type"] = "application/json"
with ExitStack() as stack:
session = stack.enter_context(requests.Session())
files = None
if False:
image = stack.enter_context(open(os.environ["SHOPENTLY_IMAGE_FILE"], "rb"))
if os.fstat(image.fileno()).st_size > 5242880:
raise ValueError("Image exceeds 5 MiB")
files = {"file": ("article.png", image, "image/png")}
response = session.request(
'GET', base_url + '/api/v1/orders?limit=20', headers=headers,
data=body.encode("utf-8") if body is not None else None, files=files,
timeout=(5, 30), allow_redirects=False,
)
if not 200 <= response.status_code < 300:
raise RuntimeError(f"HTTP {response.status_code}; request_id={response.headers.get('X-Request-ID', '')}; retry_after={response.headers.get('Retry-After', '')}")
if False:
if response.headers.get("Content-Type") != "image/webp" or len(response.content) > 5242880:
raise ValueError("Unexpected image response")
with open(os.environ["SHOPENTLY_OUTPUT_FILE"], "xb") as output:
output.write(response.content)
else:
result = response.json() if response.content else None
print(json.dumps(result, ensure_ascii=False, indent=2))
回應示例 200
{
"data": [
{
"created_at": "2026-10-19T10:00:00Z",
"customer": {
"email": "customer@example.invalid",
"first_name": "Example",
"last_name": "Example",
"phone": null
},
"delivery": {
"amount": {
"amount": "0.00",
"currency": "PLN",
"minor_units": 2
},
"dates": {
"dispatch_timezone": "Europe/Warsaw",
"estimated_delivery_from": "2026-10-20",
"estimated_delivery_to": "2026-10-21",
"planned_dispatch_on": "2026-10-19"
},
"method_code": "shipping-old",
"method_name": "Historic carrier",
"pickup_point": null,
"recipient_mode": "full_address"
},
"discount_amount": {
"amount": "24.60",
"currency": "PLN",
"minor_units": 2
},
"id": "order-0000",
"lifecycle_state": "placed",
"locale": "pl",
"market_id": "market-pl",
"number": "0001",
"payment": {
"amount": {
"amount": "329.40",
"currency": "PLN",
"minor_units": 2
},
"environment": "live",
"method_code": "payment-old",
"method_name": "Historic method",
"paid_at": null,
"status": "unpaid",
"updated_at": "2026-10-19T10:00:00Z",
"version": 0
},
"prices_include_tax": true,
"shipping_discount_amount": {
"amount": "24.60",
"currency": "PLN",
"minor_units": 2
},
"status": {
"id": "status-0",
"name": "Status 0",
"updated_at": "2026-10-19T10:00:00Z",
"version": 1
},
"subtotal": {
"amount": "329.40",
"currency": "PLN",
"minor_units": 2
},
"tax": {
"amount": "49.40",
"currency": "PLN",
"minor_units": 2
},
"tax_country_code": "PL",
"total": {
"amount": "329.40",
"currency": "PLN",
"minor_units": 2
}
}
],
"meta": {
"pagination": {
"has_more": false,
"limit": 20,
"next_cursor": null
},
"request_id": "example"
}
}
工作原理
- 集合提供訂單摘要,以及訂單號、狀態、支付狀態和建立時間篩選。
- 訂單列表和詳細資料均包含 delivery.dates。YYYY-MM-DD 格式的日期為計畫日期,不代表已出貨。目前日期優先;舊訂單使用已儲存的估計。已清除或未知的值為 null。詳細資料還包含所有訂單項目和商品圖片。
- 從 /api/v1/order-statuses 取得有效狀態識別碼。
- 訂單狀態和支付狀態使用不同的 PATCH 端點及權限。
- 修改記錄中的支付狀態不會從銀行卡扣款,也不會通過支付服務商發起退款。
訂單 · 合計
金額和稅率取自已儲存的訂單,包括訂單項目的更正。缺少的歷史資料為 null,不會用目前商品目錄的稅率補齊。金額始終維持為十進位字串。
清單傳回摘要。針對每個結果取得 GET /api/v1/orders/{order_id},以匯出完整的金額明細。GET 重試次數有限,並遵循 Retry-After。依建立日期匯出不會同步之後的更正。
參數
查詢參數
limit整數選填此頁記錄數上限。
minimum:1maximum:100cursor字串 null選填上一頁回傳的不透明續頁值。
字串:minLength:1maxLength:1024number字串 null選填面向使用者的訂單號或申請編號。
字串:minLength:1maxLength:48status_id字串 null選填從相應狀態字典取得的識別碼。
約束 · 字串 1
pattern"^[a-z0-9][a-z0-9_-]{0,62}$"
payment_status字串 null選填記錄的支付狀態。
約束 · 字串 1
enum["unpaid", "paid", "failed", "refunded"]
created_from字串 null選填建立時間篩選的起點。
字串:format:"date-time"created_to字串 null選填建立時間篩選的終點。
字串:format:"date-time"
此操作不接受 JSON 請求本文。
回應
回應 200
完整模型: ApiResponse_list_OrderSummaryData__
data陣列 <OrderSummaryData> 必填成功回應的資料。
欄位 ·
datacreated_at字串必填建立時間。
format:"date-time"customerCustomerData必填此資源記錄的客戶資訊。
deliveryShippingData必填配送方式及相關資訊。
discount_amountMoneyData必填以 JSON 字串編碼的十進位金額;僅在允許時使用 null。
id字串必填資源識別碼;請保留回傳的原值。
lifecycle_stateOrderLifecycleState必填業務生命週期狀態。
locale字串必填本次請求選擇的語言。
market_id字串必填上下文端點回傳的市場識別碼。
number字串必填面向使用者的訂單號或申請編號。
paymentPaymentData必填訂單中記錄的支付詳情。
prices_include_tax布林值必填列出的價格是否含稅。
shipping_discount_amountMoneyData必填以 JSON 字串編碼的十進位金額;僅在允許時使用 null。
statusOrderStatusData必填此操作接受的狀態。
subtotalMoneyData必填加入回應中所示附加組成部分之前的金額。
taxMoneyData必填稅務資訊。
tax_country_code字串 null必填課稅國家 · 已儲存的訂單資料 · ISO 3166-1 alpha-2; null.
totalMoneyData必填總金額。
metaContextPageMetaContextMetaPageMetaRequestMeta必填回應元資料。
欄位 ·
metalocale字串必填本次請求選擇的語言。
market_code字串必填上下文端點回傳的市場代碼。
market_id字串必填上下文端點回傳的市場識別碼。
paginationPagination必填遊標分頁元資料。
request_id字串必填申請識別碼;在回應元資料中表示 HTTP 請求識別碼。
minLength:1maxLength:100
locale字串必填本次請求選擇的語言。
market_code字串必填上下文端點回傳的市場代碼。
market_id字串必填上下文端點回傳的市場識別碼。
request_id字串必填申請識別碼;在回應元資料中表示 HTTP 請求識別碼。
minLength:1maxLength:100
paginationPagination必填遊標分頁元資料。
request_id字串必填申請識別碼;在回應元資料中表示 HTTP 請求識別碼。
minLength:1maxLength:100
HTTP 狀態
200- 請求成功 架構
400- 無效請求
401- 需要身分驗證
403- 權限不足
404- 找不到資源
409- 版本衝突
422- 驗證失敗
429- 超出請求限制
其他 HTTP 狀態 (7)
405- 不允許的方法
413- 請求過大
415- 不支援的格式
500- 伺服器錯誤
502- API 閘道錯誤
503- 服務無法使用
504- 閘道逾時
錯誤目錄: ErrorResponse
請求標頭與回應標頭
401
WWW-Authenticate字串選填伺服器要求的身份驗證方案。
405
Allow字串選填此資源支援的 HTTP 方法。
429, 503
Retry-After整數選填重試前最少等待的秒數。
minimum:0