title: "简介" post_status: publish comment_status: open taxonomy: category: - woocommerce-rest-api post_tag: - V1 - Includes - Source
简介
自 v2.1 版本起,WooCommerce 包含了一个 REST API,允许以 JSON 或 XML 格式访问商店数据。当前版本为只读(更新订单状态是唯一的例外),但未来版本将允许更新、创建和删除资源。
要求
您必须使用 WooCommerce 2.1 版本,并且必须在 WooCommerce > 设置中启用 REST API。您必须启用美观固定链接(默认固定链接将无法工作)。
架构
可通过以下端点访问该 API:
https://www.example.com/wc-api/v1/
您可以通过 HTTP 或 HTTPS 访问 API。建议尽可能使用 HTTPS,API 索引会声明站点是否支持 SSL。
版本
当前版本为 v1,在端点 URL 中占据首位。仅在进行主要版本发布时才会更改。
响应
默认响应格式为 JSON。您可以通过将 HTTP ACCEPT 标头设置为 application/xml 或 text/xml 来更改为 XML。成功的请求将返回 200 OK HTTP 状态码。请注意,XML 响应的结构略有不同。
关于响应的一些通用信息:
-
日期以 UTC 时区的 RFC3339 格式返回:
YYYY-MM-DDTHH:MM:SSZ -
资源 ID 以整数形式返回。
-
任何十进制货币金额,例如价格或总计,都以保留两位小数的字符串形式返回。小数分隔符(通常是
.或,)由站点控制,并包含在 API 索引中。这是有意为之,旨在使客户端更容易本地化 API 数据。如果您需要对返回的数据进行计算(例如,在执行任何计算之前,将使用逗号作为小数点的字符串金额进行转换),则可能需要在您的实现中考虑到这一点。 -
其他数量,例如项目计数,以整数形式返回。
-
空白字段通常包含为
null,而不是空字符串或被省略。
认证
根据网站是否支持 SSL,API 提供两种认证方式。请记住,索引端点会指示网站是否支持 SSL。
通过 HTTPS
您可以使用 HTTP 基本认证,将 API 消费者密钥作为用户名,API 消费者密钥作为密码:
$ curl https://www.example.com/wc-api/v1/orders \
-u consumer_key:consumer_secret
有时某些服务器可能无法正确解析 Authorization 标头(如果在通过 SSL 认证时看到“Consumer key is missing”错误,则说明服务器存在问题)。在 WooCommerce 2.1.7+ 版本中,您可以将消费者密钥/密钥作为查询字符串参数提供:
$ curl https://www.example.com/wc-api/v1/orders?consumer_key=123&consumer_secret=abc
通过 HTTP
您必须使用 OAuth 1.0a "单腿" 认证 来确保 API 凭据不被截获。通常,您可以使用所选语言的任何标准 OAuth 1.0a 库来处理认证,或按照以下说明生成必要的参数。
生成 OAuth 签名
1) 设置请求的 HTTP 方法:
GET
2) 设置你的基础请求 URI —— 这是不包含查询字符串参数的完整请求 URI —— 并根据 RFC 3986 进行 URL 编码:
http://www.example.com/wc-api/v1/orders
编码后:
http%3A%2F%2Fwww.example.com%2Fwc-api%2Fv1%2Forders
3) 收集并规范化你的查询字符串参数。这包括除签名外的所有 oauth_* 参数。参数应根据 RFC 3986(PHP 中的 rawurlencode)进行 URL 编码,并且百分号(%)字符应进行双重编码(例如 % 变为 %25)。
4) 按字节顺序对参数进行排序(PHP 中使用 uksort( $params, 'strcmp' ))
5) 用编码后的等号(%3D)连接每个参数:
oauth_signature_method%3DHMAC-SHA1
6) 用编码后的与符号(%26)连接每个参数的键/值对:
oauth_consumer_key%3Dabc123%26oauth_signature_method%3DHMAC-SHA1
7) 通过用未编码的与符号(&)连接 HTTP 方法、编码后的基础请求 URI 和编码后的参数字符串,形成待签名字符串:
GET&http%3A%2F%2Fwww.example.com%2Fwc-api%2Fv1%2Forders&oauth_consumer_key%3Dabc123%26oauth_signature_method%3DHMAC-SHA1
8) 使用待签名字符串和你的消费者密钥生成签名
如果你在生成正确签名时遇到问题,应检查待签名字符串是否存在编码错误。认证源代码也有助于理解如何正确生成签名。
OAuth 使用提示
-
OAuth 参数必须作为查询字符串参数添加,而不能包含在 Authorization 头中。
-
必需的参数包括:
oauth_consumer_key、oauth_timestamp、oauth_nonce、oauth_signature和oauth_signature_method。oauth_version不是必需的,必须省略。 -
仅接受 HMAC-SHA1 或 HMAC-SHA256 哈希算法。
-
OAuth nonce 可以是任何随机生成的 32 字符(推荐)字符串,且对于 consumer key 是唯一的。在 Twitter API 论坛上阅读更多关于生成 nonce 的建议。
-
OAuth 时间戳应为请求时的 Unix 时间戳。API 将拒绝包含时间戳超出 15 分钟窗口的请求,以防止重放攻击。
-
在构建用于签名的 base string 时,必须使用索引提供的店铺 URL,因为服务器将使用此 URL。(例如,如果店铺 URL 包含
www子域名,则应在请求中使用它) -
某些 OAuth 库在生成签名前会在提供的密钥后添加一个 & 符号。这不符合 OAuth 规范,应在生成签名前移除该 & 符号。
-
您可以使用 LinkedIn 的 OAuth 测试控制台 测试生成的签名——将成员令牌/密钥留空。
-
Twitter 提供了关于使用 OAuth 1.0a 生成签名 的详细说明,但请记住此实现不使用令牌。
-
请注意,根据 OAuth 规范,请求体不参与签名,有关原因请参阅 Google 的 OAuth 1.0 扩展。
参数
API 端点可以接受可选参数,这些参数可以作为 HTTP 查询字符串参数传递:
GET /orders?status=completed
所有端点都接受一个 filter 参数,该参数使用方括号来限定各个过滤器,例如日期过滤:
GET /orders?filter[created_at_min]=2013-11-01
可以包含多个 filter 参数,并与其他参数混合使用:
GET /orders?status=completed&filter[created_at_min]=2013-11-01&filter[created_at_max]=2013-11-30
您可以使用 q 过滤器参数进行关键字搜索:
GET /products?filter[q]=search-keyword
默认情况下,资源元数据被排除在外,但可以通过 meta 过滤器参数包含:
GET /orders?filter[meta]=true
受保护的元数据(键以下划线为前缀的元数据)不包含在响应中。reports 端点不支持元数据。
您可以使用 fields 参数限制响应中返回的字段:
GET /orders?fields=id
要包含多个字段,请用逗号分隔:
GET /orders?fields=id,status
您可以使用点表示法指定子字段:
GET /orders?fields=id,status,payment_details.method_title
对于具有多个结构体的资源(例如订单的行项目),无法限制子字段。例如,这将只返回行项目,但每个行项目都将包含完整的信息集,而不仅仅是产品 ID:
GET /orders?fields=line_items.product_id
使用参数时的一些通用准则:
-
日期应以 UTC 时区的 RFC3339 格式提供:
YYYY-MM-DDTHH:MM:SSZ。如果需要,可以省略时间和时区。 -
使用
q过滤器进行搜索时,搜索词应进行 URL 编码,因为它们将在内部使用urldecode进行解码。
错误
访问 API 时偶尔可能会遇到错误。共有四种可能的类型:
- 无效请求,例如使用不支持的 HTTP 方法将导致
400 Bad Request:
{
"errors" : [
{
"code" : "woocommerce_api_unsupported_method",
"message" : "Unsupported request method"
}
]
}
- 身份验证或权限错误,例如 API 密钥不正确将导致
401 Unauthorized:
{
"errors" : [
{
"code" : "woocommerce_api_authentication_error",
"message" : "Consumer Key is invalid"
}
]
}
- 请求不存在的资源或缺少必需参数将导致
404 Not Found:
{
"errors" : [
{
"code" : "woocommerce_api_invalid_order",
"message" : "Invalid order"
}
]
}
- 由于服务器错误而无法处理的请求将导致
500 Internal Server Error:
{
"errors" : [
{
"code" : "woocommerce_api_invalid_handler",
"message" : "The handler for the route is invalid"
}
]
}
错误会返回适当的 HTTP 状态码和响应对象,其中包含 code 和 message 属性。如果某个端点有任何自定义错误,它们会与该端点一同记录。
HTTP 动词
API 为每个操作使用相应的 HTTP 动词:
HEAD- 可用于任何端点,仅返回 HTTP 头部信息GET- 用于检索资源PUT- 用于更新资源,目前仅支持orders/#{id}端点
在未来的 API 版本中,将支持 POST 和 DELETE。
分页
返回多个项目的请求默认会分页为每页 10 项。站点管理员可以通过修改 posts_per_page 选项来更改此默认值。或者,也可以通过 ?filter[limit] 参数指定每页的项目数:
GET /orders?filter[limit]=15
您可以使用 ?page 参数指定后续页面:
GET /orders?page=2
您还可以使用 ?filter[offset] 参数指定从第一个资源开始的偏移量:
GET /orders?filter[offset]=5
页码从 1 开始计数,省略 ?page 参数将返回第一页。
资源总数和总页数始终包含在 X-WC-Total 和 X-WC-TotalPages HTTP 头中。
链接头部
分页信息包含在链接头部中。建议您尽可能遵循这些值,而不是自行构建 URL。
Link: <https://www.example.com/wc-api/v1/products?page=2>; rel="next",
<https://www.example.com/wc-api/v1/products?page=3>; rel="last"`
为便于阅读而包含换行
可能的 rel 值包括:
next- 显示下一页结果的 URLlast- 显示最后一页结果的 URLfirst- 显示第一页结果的 URLprev- 显示上一页结果的 URL
JSON-P Support
The API supports JSON-P by default. You can specify the callback using the ?_jsonp parameter for GET requests to have the response wrapped in a JSON function:
GET /orders/count?_jsonp=ordersCount
ordersCount({"count":8})
If the site administrator has chosen to disable it, you will receive a400 Bad Request error:
{
"errors" : [
{
"code" : "woocommerce_api_jsonp_disabled",
"message" : "JSONP support is disabled on this site"
}
]
}
If your callback contains invalid characters, you will receive a 400 Bad Request error:
{
"errors" : [
{
"code" : "woocommerce_api_jsonp_callback_invalid",
"message" : "The JSONP callback function is invalid"
}
]
}
端点
该 API 支持 5 个主要资源,每个资源都有一组相关的端点。
索引
API 索引提供有关站点可用端点的信息,以及特定于商店的信息。访问 API 索引无需身份验证,但如果 REST API 被禁用,您将收到 404 Not Found 错误:
{
"errors" : [
{
"code" : "woocommerce_api_disabled",
"message" : "The WooCommerce API is disabled on this site"
}
]
}
店铺属性
routes:按相对 URL 索引的站点可用端点列表。每个端点指定支持的 HTTP 方法以及规范 URL。dimension_unit:为产品尺寸设置的单位。有效单位为cm、m、cm、mm、in和ydtax_included:如果价格包含税则为 true,否则为 falsessl_enabled:如果站点启用了 SSL 则为 true,否则为 falsetimezone:站点的时区currency_format:货币符号,HTML 编码weight_unit:为产品重量设置的单位。有效单位为kg、g、lbs、ozdescription:站点的描述name:站点的名称URL:站点的 URLpermalinks_enabled:站点是否启用了美观的固定链接,如果为 false,API 将无法正常工作wc_version:活动的 WooCommerce 版本
GET /
获取一组商店信息:
{
"store" : {
"routes" : {
"/customers" : {
"supports" : [
"HEAD",
"GET"
],
"meta" : {
"self" : "https://www.example.com/wc-api/v1/customers"
}
},
"/coupons/count" : {
"supports" : [
"HEAD",
"GET"
],
"meta" : {
"self" : "https://www.example.com/wc-api/v1/coupons/count"
}
},
"/orders/count" : {
"supports" : [
"HEAD",
"GET"
],
"meta" : {
"self" : "https://www.example.com/wc-api/v1/orders/count"
}
},
"/products/" : {
"supports" : [
"HEAD",
"GET"
]
},
"/orders/
}, "description" : "万物皆可 WooCommerce!", "name" : "WooCommerce", "URL" : "http://www.example.com" } }
## 优惠券
### 优惠券属性
* `expiry_date`: 优惠券的过期日期
* `individual_use`: 如果优惠券只能单独使用则为 true,否则为 false
* `exclude_product_category_ids`: 此优惠券无法应用到的产品类别 ID 列表
* `amount`: 优惠券的金额
* `code`: 优惠券代码,在购物车/结账页面输入以应用折扣
@TODO
### `GET /coupons`
Retrieve a list of coupons:
"coupons" : [ { "expiry_date" : "2013-11-22T00:00:00Z", "individual_use" : false, "exclude_product_category_ids" : [], "amount" : "5.00", "code" : "test123", "product_category_ids" : [ 22 ], "updated_at" : "2013-11-23T21:08:10Z", "limit_usage_to_x_items" : 0, "product_ids" : [ 73 ], "exclude_sale_items" : false, "type" : "fixed_cart", "apply_before_tax" : false, "minimum_amount" : "0.00", "id" : 137, "exclude_product_ids" : [], "usage_limit" : null, "usage_count" : 0, "created_at" : "2013-11-18T15:38:53Z", "usage_limit_per_user" : null, "enable_free_shipping" : false, "customer_emails" : [] } ] }
### `GET /coupons/count`
获取所有优惠券的数量:
{ "count" : 3 }
### `GET /coupons/#{id}`
### `GET /coupons/code/{code}`
根据其 ID 或代码检索单个优惠券。
请注意,优惠券代码可能包含空格、短横线和下划线,应进行 URL 编码。
{ "coupon" : { "expiry_date" : "2013-11-22T00:00:00Z", "individual_use" : false, "exclude_product_category_ids" : [], "amount" : "5.00", "code" : "test123", "product_category_ids" : [ 22 ], "updated_at" : "2013-11-23T21:08:10Z", "limit_usage_to_x_items" : 0, "product_ids" : [ 73 ], "exclude_sale_items" : false, "type" : "fixed_cart", "apply_before_tax" : false, "minimum_amount" : "0.00", "id" : 137, "exclude_product_ids" : [], "usage_limit" : null, "usage_count" : 0, "created_at" : "2013-11-18T15:38:53Z", "usage_limit_per_user" : null, "enable_free_shipping" : false, "customer_emails" : [] } }
## 客户
所有端点(客户订单除外)均支持通过 `created_at_min` 和 `created_at_max` 作为 `?filter[]` 参数进行日期筛选。例如:`?filter[created_at_min]=2013-12-01`
### 客户属性
@待办事项
### `GET /customers`
Retrieve a list of customers:
{ "customers" : [ { "id" : 4, "last_order_date" : "2013-12-10T18:58:00Z", "avatar_url" : "https://secure.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=96", "total_spent" : "0.00", "created_at" : "2013-12-10T18:58:07Z", "orders_count" : 0, "billing_address" : { "phone" : "215-523-4132", "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "email" : "thedon@mailinator.com", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "shipping_address" : { "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "first_name" : "Don", "username" : "thedon", "last_name" : "Draper", "last_order_id" : "113", "email" : "thedon@mailinator.com" } ] }
### `GET /customers/count`
获取所有客户的数量:
{ "count" : 18 }
### `GET /customers/#{id}`
根据 ID 获取单个客户信息:
{ "customer" : { "id" : 4, "last_order_date" : "2013-12-10T18:58:00Z", "avatar_url" : "https://secure.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=96", "total_spent" : "0.00", "created_at" : "2013-12-10T18:58:07Z", "orders_count" : 0, "billing_address" : { "phone" : "215-523-4132", "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "email" : "thedon@mailinator.com", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "shipping_address" : { "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "first_name" : "Don", "username" : "thedon", "last_name" : "Draper", "last_order_id" : "113", "email" : "thedon@mailinator.com" } }
### `GET /customers/#{id}/orders`
根据客户 ID 获取其订单列表:
{ "orders" : [ { "completed_at" : "2013-12-10T18:59:30Z", "tax_lines" : [], "status" : "processing", "total" : "20.00", "cart_discount" : "0.00", "customer_ip" : "127.0.0.1", "total_discount" : "0.00", "updated_at" : "2013-12-10T18:59:30Z", "currency" : "USD", "total_shipping" : "0.00", "customer_user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36", "line_items" : [ { "product_id" : 31, "quantity" : 1, "id" : 7, "subtotal" : "20.00", "tax_class" : null, "sku" : "", "total" : "20.00", "name" : "Ninja Silhouette", "total_tax" : "0.00" } ], "customer_id" : "4", "total_tax" : "0.00", "order_number" : "#113", "shipping_methods" : "Free Shipping", "shipping_address" : { "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "payment_details" : { "method_title" : "Cheque Payment", "method_id" : "cheque", "paid" : false }, "id" : 113, "shipping_tax" : "0.00", "cart_tax" : "0.00", "fee_lines" : [], "total_line_items_quantity" : 1, "shipping_lines" : [ { "method_title" : "Free Shipping", "id" : 8, "method_id" : "free_shipping", "total" : "0.00" } ], "customer" : { "id" : 4, "last_order_date" : "2013-12-10T18:58:00Z", "avatar_url" : "https://secure.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=96", "total_spent" : "0.00", "created_at" : "2013-12-10T18:58:07Z", "orders_count" : 0, "billing_address" : { "phone" : "215-523-4132", "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "email" : "thedon@mailinator.com", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "shipping_address" : { "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "first_name" : "Don", "username" : "thedon", "last_name" : "Draper", "last_order_id" : "113", "email" : "thedon@mailinator.com" }, "note" : "", "coupon_lines" : [], "order_discount" : "0.00", "created_at" : "2013-12-10T18:58:00Z", "view_order_url" : "https://www.example.com/my-account/view-order/113", "billing_address" : { "phone" : "215-523-4132", "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "email" : "thedon@mailinator.com", "address_2" : "", "state" : "NY", "first_name" : "Don" } } ] }
## 订单
所有端点(订单备注除外)都支持完整的日期筛选器集合(`created_at_min`、`created_at_max`、`updated_at_min`、`updated_at_max`)作为 `?filter[]` 参数。例如:`?filter[created_at_min]=2013-12-01`
### 订单属性
@TODO
### `GET /orders`
获取订单列表
您可以使用 `?status?` 参数将返回的订单限制为特定的订单状态。默认的 WooCommerce 订单状态包括 `pending`、`on-hold`、`processing`、`completed`、`refunded`、`failed` 和 `cancelled`。支持自定义订单状态。
{ "orders" : [ { "completed_at" : "2013-12-10T18:59:30Z", "tax_lines" : [], "status" : "processing", "total" : "20.00", "cart_discount" : "0.00", "customer_ip" : "127.0.0.1", "total_discount" : "0.00", "updated_at" : "2013-12-10T18:59:30Z", "currency" : "USD", "total_shipping" : "0.00", "customer_user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36", "line_items" : [ { "product_id" : 31, "quantity" : 1, "id" : 7, "subtotal" : "20.00", "tax_class" : null, "sku" : "", "total" : "20.00", "name" : "Ninja Silhouette", "total_tax" : "0.00" } ], "customer_id" : "4", "total_tax" : "0.00", "order_number" : "#113", "shipping_methods" : "Free Shipping", "shipping_address" : { "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "payment_details" : { "method_title" : "Cheque Payment", "method_id" : "cheque", "paid" : false }, "id" : 113, "shipping_tax" : "0.00", "cart_tax" : "0.00", "fee_lines" : [], "total_line_items_quantity" : 1, "shipping_lines" : [ { "method_title" : "Free Shipping", "id" : 8, "method_id" : "free_shipping", "total" : "0.00" } ], "customer" : { "id" : 4, "last_order_date" : "2013-12-10T18:58:00Z", "avatar_url" : "https://secure.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=96", "total_spent" : "0.00", "created_at" : "2013-12-10T18:58:07Z", "orders_count" : 0, "billing_address" : { "phone" : "215-523-4132", "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "email" : "thedon@mailinator.com", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "shipping_address" : { "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "first_name" : "Don", "username" : "thedon", "last_name" : "Draper", "last_order_id" : "113", "email" : "thedon@mailinator.com" }, "note" : "", "coupon_lines" : [], "order_discount" : "0.00", "created_at" : "2013-12-10T18:58:00Z", "view_order_url" : "https://www.example.com/my-account/view-order/113", "billing_address" : { "phone" : "215-523-4132", "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "email" : "thedon@mailinator.com", "address_2" : "", "state" : "NY", "first_name" : "Don" } } ] }
### `GET /orders/count`
获取所有订单的数量:
{ "count" : 27 }
### `GET /orders/#{id}`
根据 ID 获取指定的单个订单:
{ "order" : { "completed_at" : "2013-12-10T18:59:30Z", "tax_lines" : [], "status" : "processing", "total" : "20.00", "cart_discount" : "0.00", "customer_ip" : "127.0.0.1", "total_discount" : "0.00", "updated_at" : "2013-12-10T18:59:30Z", "currency" : "USD", "total_shipping" : "0.00", "customer_user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36", "line_items" : [ { "product_id" : 31, "quantity" : 1, "id" : 7, "subtotal" : "20.00", "tax_class" : null, "sku" : "", "total" : "20.00", "name" : "Ninja Silhouette", "total_tax" : "0.00" } ], "customer_id" : "4", "total_tax" : "0.00", "order_number" : "#113", "shipping_methods" : "Free Shipping", "shipping_address" : { "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "payment_details" : { "method_title" : "Cheque Payment", "method_id" : "cheque", "paid" : false }, "id" : 113, "shipping_tax" : "0.00", "cart_tax" : "0.00", "fee_lines" : [], "total_line_items_quantity" : 1, "shipping_lines" : [ { "method_title" : "Free Shipping", "id" : 8, "method_id" : "free_shipping", "total" : "0.00" } ], "customer" : { "id" : 4, "last_order_date" : "2013-12-10T18:58:00Z", "avatar_url" : "https://secure.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=96", "total_spent" : "0.00", "created_at" : "2013-12-10T18:58:07Z", "orders_count" : 0, "billing_address" : { "phone" : "215-523-4132", "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "email" : "thedon@mailinator.com", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "shipping_address" : { "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "first_name" : "Don", "username" : "thedon", "last_name" : "Draper", "last_order_id" : "113", "email" : "thedon@mailinator.com" }, "note" : "", "coupon_lines" : [], "order_discount" : "0.00", "created_at" : "2013-12-10T18:58:00Z", "view_order_url" : "https://www.example.com/my-account/view-order/113", "billing_address" : { "phone" : "215-523-4132", "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "email" : "thedon@mailinator.com", "address_2" : "", "state" : "NY", "first_name" : "Don" } } }
### `PUT /orders/#{id}?status={status}`
根据订单 ID 更新其状态。
请求体应为 JSON 格式:
{ "status":"completed" }
如果成功,将返回更新后的订单:
{ "order" : { "completed_at" : "2013-12-10T18:59:30Z", "tax_lines" : [], "status" : "completed", "total" : "20.00", "cart_discount" : "0.00", "customer_ip" : "127.0.0.1", "total_discount" : "0.00", "updated_at" : "2013-12-10T18:59:30Z", "currency" : "USD", "total_shipping" : "0.00", "customer_user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36", "line_items" : [ { "product_id" : 31, "quantity" : 1, "id" : 7, "subtotal" : "20.00", "tax_class" : null, "sku" : "", "total" : "20.00", "name" : "Ninja Silhouette", "total_tax" : "0.00" } ], "customer_id" : "4", "total_tax" : "0.00", "order_number" : "#113", "shipping_methods" : "Free Shipping", "shipping_address" : { "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "payment_details" : { "method_title" : "Cheque Payment", "method_id" : "cheque", "paid" : false }, "id" : 113, "shipping_tax" : "0.00", "cart_tax" : "0.00", "fee_lines" : [], "total_line_items_quantity" : 1, "shipping_lines" : [ { "method_title" : "Free Shipping", "id" : 8, "method_id" : "free_shipping", "total" : "0.00" } ], "customer" : { "id" : 4, "last_order_date" : "2013-12-10T18:58:00Z", "avatar_url" : "https://secure.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=96", "total_spent" : "0.00", "created_at" : "2013-12-10T18:58:07Z", "orders_count" : 0, "billing_address" : { "phone" : "215-523-4132", "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "email" : "thedon@mailinator.com", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "shipping_address" : { "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "address_2" : "", "state" : "NY", "first_name" : "Don" }, "first_name" : "Don", "username" : "thedon", "last_name" : "Draper", "last_order_id" : "113", "email" : "thedon@mailinator.com" }, "note" : "", "coupon_lines" : [], "order_discount" : "0.00", "created_at" : "2013-12-10T18:58:00Z", "view_order_url" : "https://www.example.com/my-account/view-order/113", "billing_address" : { "phone" : "215-523-4132", "city" : "New York", "country" : "US", "address_1" : "512 First Avenue", "last_name" : "Draper", "company" : "SDCP", "postcode" : "12534", "email" : "thedon@mailinator.com", "address_2" : "", "state" : "NY", "first_name" : "Don" } } }
### `GET /orders/#{id}/notes`
Retrieve a list of notes for an order specified by it's ID:
{ "order_notes" : [ { "note" : "Order status changed from processing to completed.", "id" : "47", "created_at" : "2013-12-10T20:08:06Z", "customer_note" : false }, { "note" : "Order status changed from on-hold to processing.", "id" : "46", "created_at" : "2013-12-10T18:59:30Z", "customer_note" : false }, { "note" : "Awaiting cheque payment Order status changed from pending to on-hold.", "id" : "45", "created_at" : "2013-12-10T18:58:23Z", "customer_note" : false } ] }
## 产品
所有端点(除评论外)均支持完整的日期筛选器集合(`created_at_min`、`created_at_max`、`updated_at_min`、`updated_at_max`)作为 `?filter[]` 参数。例如:`?filter[created_at_min]=2013-12-01`
### 产品属性
@TODO
### `GET /products`
获取产品列表
您可以使用 `?type` 参数来指定仅返回特定产品类型。默认的 WooCommerce 产品类型包括:`simple`、`variable`、`grouped` 和 `external`。支持自定义产品类型。
{ "products" : [ { "related_ids" : [ 87, 93, 96, 93, 83 ], "variations" : [], "categories" : [ "Music", "Singles" ], "shipping_required" : true, "id" : 99, "parent" : [], "regular_price" : "3.00", "weight" : null, "total_sales" : 0, "sku" : "", "rating_count" : 2, "managing_stock" : false, "title" : "Woo Single #2", "backordered" : false, "on_sale" : true, "status" : "publish", "download_limit" : 0, "taxable" : false, "reviews_allowed" : true, "description" : "
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
\n", "purchaseable" : true, "sale_price" : "2.00", "type" : "simple", "permalink" : "https://www.example.com/product/woo-single-2/", "catalog_visibility" : "visible", "download_expiry" : 0, "dimensions" : { "length" : "", "height" : "", "unit" : "in", "width" : "" }, "cross_sell_ids" : [], "price" : "2.00", "updated_at" : "2013-06-07T11:38:12Z", "attributes" : [], "shipping_class" : "", "virtual" : false, "downloadable" : false, "upsell_ids" : [], "created_at" : "2013-06-07T11:38:12Z", "tax_class" : "", "tags" : [], "price_html" : "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
\n", "downloads" : [], "tax_status" : "taxable", "average_rating" : "4.50", "download_type" : "", "shipping_taxable" : true, "purchase_note" : "", "shipping_class_id" : null, "visible" : true, "backorders_allowed" : false, "images" : [ { "position" : 0, "id" : 100, "created_at" : "2013-06-07T11:37:51Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/cd_6_angle.jpg", "title" : "cd_6_angle", "alt" : "", "updated_at" : "2013-06-07T11:37:51Z" }, { "position" : 1, "id" : 101, "created_at" : "2013-06-07T11:38:03Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/cd_6_flat.jpg", "title" : "cd_6_flat", "alt" : "", "updated_at" : "2013-06-07T11:38:03Z" } ], "stock_quantity" : 0, "featured" : false } ] }### `GET /products/count`
获取所有产品的数量
你可以使用 `?type` 参数来指定仅返回特定产品类型。默认的 WooCommerce 产品类型包括:`simple`、`variable`、`grouped` 和 `external`。支持自定义产品类型。
{ "count" : 23 }
### `GET /products/#{id}`
根据产品 ID 获取指定产品
简单产品、分组产品和外部产品的 `variations` 属性将返回空数组:
{ "product" : { "related_ids" : [ 93, 90, 93, 87, 83 ], "variations" : [], "categories" : [ "Music", "Singles" ], "shipping_required" : true, "id" : 99, "parent" : [], "regular_price" : "3.00", "weight" : null, "total_sales" : 0, "sku" : "", "rating_count" : 2, "managing_stock" : false, "title" : "Woo Single #2", "backordered" : false, "on_sale" : true, "status" : "publish", "download_limit" : 0, "taxable" : false, "reviews_allowed" : true, "description" : "
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
\n", "purchaseable" : true, "sale_price" : "2.00", "type" : "simple", "permalink" : "https://www.example.com/product/woo-single-2/", "catalog_visibility" : "visible", "download_expiry" : 0, "dimensions" : { "length" : "", "height" : "", "unit" : "in", "width" : "" }, "cross_sell_ids" : [], "price" : "2.00", "updated_at" : "2013-06-07T11:38:12Z", "attributes" : [], "shipping_class" : "", "virtual" : false, "downloadable" : false, "upsell_ids" : [], "created_at" : "2013-06-07T11:38:12Z", "tax_class" : "", "tags" : [], "price_html" : "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
\n", "downloads" : [], "tax_status" : "taxable", "average_rating" : "4.50", "download_type" : "", "shipping_taxable" : true, "purchase_note" : "", "shipping_class_id" : null, "visible" : true, "backorders_allowed" : false, "images" : [ { "position" : 0, "id" : 100, "created_at" : "2013-06-07T11:37:51Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/cd_6_angle.jpg", "title" : "cd_6_angle", "alt" : "", "updated_at" : "2013-06-07T11:37:51Z" }, { "position" : 1, "id" : 101, "created_at" : "2013-06-07T11:38:03Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/cd_6_flat.jpg", "title" : "cd_6_flat", "alt" : "", "updated_at" : "2013-06-07T11:38:03Z" } ], "stock_quantity" : 0, "featured" : false } }Variable products will return individual variations in the `variations` property:
{ "product" : { "related_ids" : [ 50, 60, 53, 19, 15 ], "variations" : [ { "attributes" : [ { "option" : "black", "name" : "Color" } ], "weight" : null, "sku" : "", "backordered" : false, "shipping_class" : "", "image" : [ { "position" : 0, "id" : 43, "created_at" : "2013-06-07T10:59:40Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/hoodie_7_front.jpg", "title" : "hoodie_7_front", "alt" : "", "updated_at" : "2013-06-07T10:59:40Z" } ], "updated_at" : "2013-06-07T11:00:28Z", "downloads" : [], "downloadable" : false, "regular_price" : "35.00", "permalink" : "https://www.example.com/product/ship-your-idea-2/?attribute_pa_color=black", "stock_quantity" : 0, "shipping_class_id" : null, "taxable" : false, "tax_status" : "taxable", "download_expiry" : 0, "id" : 41, "virtual" : false, "on_sale" : false, "download_limit" : 0, "in_stock" : true, "sale_price" : null, "created_at" : "2013-06-07T11:00:28Z", "price" : "35.00", "visible" : true, "dimensions" : { "length" : "", "height" : "", "unit" : "in", "width" : "" }, "tax_class" : "", "purchaseable" : true }, { "attributes" : [ { "option" : "blue", "name" : "Color" } ], "weight" : null, "sku" : "", "backordered" : false, "shipping_class" : "", "image" : [ { "position" : 0, "id" : 46, "created_at" : "2013-06-07T11:00:01Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/hoodie_1_front.jpg", "title" : "hoodie_1_front", "alt" : "", "updated_at" : "2013-06-07T11:00:01Z" } ], "updated_at" : "2013-06-07T11:00:28Z", "downloads" : [], "downloadable" : false, "regular_price" : "35.00", "permalink" : "https://www.example.com/product/ship-your-idea-2/?attribute_pa_color=blue", "stock_quantity" : 0, "shipping_class_id" : null, "taxable" : false, "tax_status" : "taxable", "download_expiry" : 0, "id" : 42, "virtual" : false, "on_sale" : true, "download_limit" : 0, "in_stock" : true, "sale_price" : "30.00", "created_at" : "2013-06-07T11:00:28Z", "price" : "30.00", "visible" : true, "dimensions" : { "length" : "", "height" : "", "unit" : "in", "width" : "" }, "tax_class" : "", "purchaseable" : true } ], "categories" : [ "Clothing", "Hoodies" ], "shipping_required" : true, "id" : 40, "parent" : [], "regular_price" : "0.00", "weight" : null, "total_sales" : 1, "sku" : "", "rating_count" : 3, "managing_stock" : false, "title" : "Ship Your Idea", "backordered" : false, "on_sale" : true, "status" : "publish", "download_limit" : 0, "taxable" : false, "reviews_allowed" : true, "description" : "
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
\n", "purchaseable" : true, "sale_price" : null, "type" : "variable", "permalink" : "https://www.example.com/product/ship-your-idea-2/", "catalog_visibility" : "visible", "download_expiry" : 0, "dimensions" : { "length" : "", "height" : "", "unit" : "in", "width" : "" }, "cross_sell_ids" : [ 22 ], "price" : "30.00", "updated_at" : "2013-06-07T11:00:28Z", "attributes" : [ { "position" : "0", "visible" : false, "variation" : true, "options" : [ "Black", "Blue" ], "name" : "Color" } ], "shipping_class" : "", "virtual" : false, "downloadable" : false, "upsell_ids" : [], "created_at" : "2013-06-07T11:00:28Z", "tax_class" : "", "tags" : [], "price_html" : "From:Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
\n", "downloads" : [], "tax_status" : "taxable", "average_rating" : "4.00", "download_type" : "", "shipping_taxable" : true, "purchase_note" : "", "shipping_class_id" : null, "visible" : true, "backorders_allowed" : false, "images" : [ { "position" : 0, "id" : 43, "created_at" : "2013-06-07T10:59:40Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/hoodie_7_front.jpg", "title" : "hoodie_7_front", "alt" : "", "updated_at" : "2013-06-07T10:59:40Z" }, { "position" : 1, "id" : 44, "created_at" : "2013-06-07T10:59:54Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/hoodie_7_back.jpg", "title" : "hoodie_7_back", "alt" : "", "updated_at" : "2013-06-07T10:59:54Z" }, { "position" : 2, "id" : 45, "created_at" : "2013-06-07T11:00:00Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/hoodie_1_back.jpg", "title" : "hoodie_1_back", "alt" : "", "updated_at" : "2013-06-07T11:00:00Z" }, { "position" : 3, "id" : 46, "created_at" : "2013-06-07T11:00:01Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/hoodie_1_front.jpg", "title" : "hoodie_1_front", "alt" : "", "updated_at" : "2013-06-07T11:00:01Z" } ], "stock_quantity" : 0, "featured" : false } }单个产品变体将返回与常规产品略有不同的格式,父级变量产品数据位于 `parent` 属性中:
{ "product" : { "related_ids" : [ 60, 50, 53, 47, 19 ], "variations" : [], "categories" : [ "Clothing", "Hoodies" ], "shipping_required" : true, "id" : 41, "parent" : { "related_ids" : [ 56, 19, 34, 60, 19 ], "variations" : [], "categories" : [ "Clothing", "Hoodies" ], "shipping_required" : true, "id" : 40, "parent" : [], "regular_price" : "0.00", "weight" : null, "total_sales" : 1, "sku" : "", "rating_count" : 3, "managing_stock" : false, "title" : "Ship Your Idea", "backordered" : false, "on_sale" : true, "status" : "publish", "download_limit" : 0, "taxable" : false, "reviews_allowed" : true, "description" : "
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
\n", "purchaseable" : true, "sale_price" : null, "type" : "variable", "permalink" : "https://www.example.com/product/ship-your-idea-2/", "catalog_visibility" : "visible", "download_expiry" : 0, "dimensions" : { "length" : "", "height" : "", "unit" : "in", "width" : "" }, "cross_sell_ids" : [ 22 ], "price" : "30.00", "updated_at" : "2013-06-07T11:00:28Z", "attributes" : [ { "position" : "0", "visible" : false, "variation" : true, "options" : [ "Black", "Blue" ], "name" : "Color" } ], "shipping_class" : "", "virtual" : false, "downloadable" : false, "upsell_ids" : [], "created_at" : "2013-06-07T11:00:28Z", "tax_class" : "", "tags" : [], "price_html" : "From:Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
\n", "downloads" : [], "tax_status" : "taxable", "average_rating" : "4.00", "download_type" : "", "shipping_taxable" : true, "purchase_note" : "", "shipping_class_id" : null, "visible" : true, "backorders_allowed" : false, "images" : [ { "position" : 0, "id" : 43, "created_at" : "2013-06-07T10:59:40Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/hoodie_7_front.jpg", "title" : "hoodie_7_front", "alt" : "", "updated_at" : "2013-06-07T10:59:40Z" }, { "position" : 1, "id" : 44, "created_at" : "2013-06-07T10:59:54Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/hoodie_7_back.jpg", "title" : "hoodie_7_back", "alt" : "", "updated_at" : "2013-06-07T10:59:54Z" }, { "position" : 2, "id" : 45, "created_at" : "2013-06-07T11:00:00Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/hoodie_1_back.jpg", "title" : "hoodie_1_back", "alt" : "", "updated_at" : "2013-06-07T11:00:00Z" }, { "position" : 3, "id" : 46, "created_at" : "2013-06-07T11:00:01Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/hoodie_1_front.jpg", "title" : "hoodie_1_front", "alt" : "", "updated_at" : "2013-06-07T11:00:01Z" } ], "stock_quantity" : 0, "featured" : false }, "regular_price" : "35.00", "weight" : null, "total_sales" : 1, "sku" : "", "rating_count" : 3, "managing_stock" : false, "title" : "Ship Your Idea", "backordered" : false, "on_sale" : false, "status" : "publish", "download_limit" : 0, "taxable" : false, "reviews_allowed" : true, "description" : "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
\n", "purchaseable" : true, "sale_price" : null, "type" : "variation", "permalink" : "https://www.example.com/product/ship-your-idea-2/?attribute_pa_color=black", "catalog_visibility" : "visible", "download_expiry" : 0, "dimensions" : { "length" : "", "height" : "", "unit" : "in", "width" : "" }, "cross_sell_ids" : [ 22 ], "price" : "35.00", "updated_at" : "2013-06-07T11:00:28Z", "attributes" : [ { "option" : "black", "name" : "Color" } ], "shipping_class" : "", "virtual" : false, "downloadable" : false, "upsell_ids" : [], "created_at" : "2013-06-07T11:00:28Z", "tax_class" : "", "tags" : [], "price_html" : "$35", "in_stock" : true, "sold_individually" : false, "short_description" : "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
\n", "downloads" : [], "tax_status" : "taxable", "average_rating" : "4.00", "download_type" : "", "shipping_taxable" : true, "purchase_note" : "", "shipping_class_id" : null, "visible" : true, "backorders_allowed" : false, "images" : [ { "position" : 0, "id" : 43, "created_at" : "2013-06-07T10:59:40Z", "src" : "https://www.example.com/wp-content/uploads/2013/06/hoodie_7_front.jpg", "title" : "hoodie_7_front", "alt" : "", "updated_at" : "2013-06-07T10:59:40Z" } ], "stock_quantity" : 0, "featured" : false } }### `GET /products/#{id}/reviews`
Retrieve a list of reviews for a product specified by it's ID:
{ "product_reviews" : [ { "review" : "Ship it!", "rating" : "3", "id" : "13", "created_at" : "2013-06-07T15:53:31Z", "verified" : false, "reviewer_name" : "Maria", "reviewer_email" : "maria@example.com" }, { "review" : "This hoodie gets me lots of looks while out in public, I got the blue one and it's awesome. Not sure if people are looking at my hoodie only, or also at my rocking bod.", "rating" : "5", "id" : "12", "created_at" : "2013-06-07T13:24:52Z", "verified" : false, "reviewer_name" : "Ryan", "reviewer_email" : "ryan@example.com" }, { "review" : "Another great quality product that anyone who see's me wearing has asked where to purchase one of their own.", "rating" : "4", "id" : "11", "created_at" : "2013-06-07T13:03:29Z", "verified" : false, "reviewer_name" : "Stuart", "reviewer_email" : "stuart@example.com" } ] }
## 报告
### 报告属性
@TODO
### `GET /reports`
获取可用报告的简单列表:
{ "reports" : [ "sales" ] }
### `GET /reports/sales`
获取销售报告
您可以指定要获取销售数据的期间,也可以指定开始/结束日期。支持的期间有:`week`、`month`、`last_month` 和 `year`。如果使用了无效的期间,则默认使用 `week`。如果未指定期间,则使用当前日期。
`GET /reports/sales?filter[period]=month` 将返回当前月份的销售数据
要返回特定开始/结束日期的销售数据,请设置 `date_min` 和 `date_max` 筛选参数:
`GET /reports/sales?filter[date_min]=2013-12-01&filter[date_max]=2013-12-09` 将返回 12 月 1 日至 12 月 9 日(含)之间的销售数据。
如果未指定结束日期,则将使用当前日期。
{ "sales" : { "total_shipping" : "0.00", "total_orders" : 3, "total_sales" : "87.00", "totals_grouped_by" : "day", "total_discount" : "0.00", "totals" : { "2013-12-02" : { "orders" : 2, "shipping" : "0.00", "sales" : "67.00", "tax" : "0.00", "discount" : "0.00", "items" : 4 }, "2013-12-08" : { "orders" : 0, "shipping" : "0.00", "sales" : "0.00", "tax" : "0.00", "discount" : "0.00", "items" : 0 }, "2013-12-01" : { "orders" : 0, "shipping" : "0.00", "sales" : "0.00", "tax" : "0.00", "discount" : "0.00", "items" : 0 }, "2013-12-07" : { "orders" : 0, "shipping" : "0.00", "sales" : "0.00", "tax" : "0.00", "discount" : "0.00", "items" : 0 }, "2013-12-06" : { "orders" : 0, "shipping" : "0.00", "sales" : "0.00", "tax" : "0.00", "discount" : "0.00", "items" : 0 }, "2013-12-05" : { "orders" : 0, "shipping" : "0.00", "sales" : "0.00", "tax" : "0.00", "discount" : "0.00", "items" : 0 }, "2013-12-04" : { "orders" : 0, "shipping" : "0.00", "sales" : "0.00", "tax" : "0.00", "discount" : "0.00", "items" : 0 }, "2013-12-10" : { "orders" : 1, "shipping" : "0.00", "sales" : "20.00", "tax" : "0.00", "discount" : "0.00", "items" : 1 }, "2013-12-03" : { "orders" : 0, "shipping" : "0.00", "sales" : "0.00", "tax" : "0.00", "discount" : "0.00", "items" : 0 }, "2013-12-09" : { "orders" : 0, "shipping" : "0.00", "sales" : "0.00", "tax" : "0.00", "discount" : "0.00", "items" : 0 } }, "total_items" : 5, "total_customers" : 1, "average_sales" : "8.70", "total_tax" : "0.00" } } ```
故障排除
- Nginx - 旧版 Nginx 配置可能导致 API 问题,详情参见此问题
工具
- WooCommerce REST API 客户端库 - Gerhard Potgieter 开发的简易 PHP 客户端库
- CocoaRestClient - 免费易用的 Mac OS X 图形界面客户端,用于与 API 交互,在测试商店启用 SSL 时尤其实用
- Paw HTTP 客户端 - 另一款优秀的 Mac OS X HTTP 客户端
了解更多
- 初始 REST API 实现 - 初始实现的 GitHub issue