跳至内容
ShopentlyLearn

获取列表 — 订单

读取“订单”的数据。结果取决于此操作的参数。

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

JSON
{
  "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: 100
默认值: 50示例: 20
cursor字符串 null可选

上一页返回的不透明续页值。

字符串:minLength: 1maxLength: 1024
number字符串 null可选

面向用户的订单号或申请编号。

字符串:minLength: 1maxLength: 48
status_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

data数组 <OrderSummaryData > 必填

成功响应的数据。

字段 · data

OrderSummaryData

created_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 必填

总金额。

metaContextPageMeta ContextMeta PageMeta RequestMeta 必填

响应元数据。

字段 · meta

ContextPageMeta

locale字符串必填

本次请求选择的语言。

market_code字符串必填

上下文端点返回的市场代码。

market_id字符串必填

上下文端点返回的市场标识符。

paginationPagination 必填

游标分页元数据。

request_id字符串必填

申请标识符;在响应元数据中表示 HTTP 请求标识符。

minLength: 1maxLength: 100

ContextMeta

locale字符串必填

本次请求选择的语言。

market_code字符串必填

上下文端点返回的市场代码。

market_id字符串必填

上下文端点返回的市场标识符。

request_id字符串必填

申请标识符;在响应元数据中表示 HTTP 请求标识符。

minLength: 1maxLength: 100

PageMeta

paginationPagination 必填

游标分页元数据。

request_id字符串必填

申请标识符;在响应元数据中表示 HTTP 请求标识符。

minLength: 1maxLength: 100

RequestMeta

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