title: "报告 #" post_status: publish comment_status: open taxonomy: category: - woocommerce-rest-api post_tag: - Wp Api V1 - Includes - Source
报告
报告 API 允许您查看所有可用的报告类型。
列出所有报告
此 API 允许您检索并查看可用报告的简单列表。
HTTP request
GET
/wp-json/wc/v1/reports
curl https://example.com/wp-json/wc/v1/reports \
-u consumer_key:consumer_secret
WooCommerce.get("reports")
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error.response.data);
});
<?php print_r($woocommerce->get('reports')); ?>
print(wcapi.get("reports").json())
woocommerce.get("reports").parsed_response
JSON response example:
[
{
"slug": "sales",
"description": "List of sales reports.",
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v1/reports/sales"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v1/reports"
}
]
}
},
{
"slug": "top_sellers",
"description": "List of top sellers products.",
"_links": {
"self": [
{
"href": "https://example.com/wp-json/wc/v1/reports/top_sellers"
}
],
"collection": [
{
"href": "https://example.com/wp-json/wc/v1/reports"
}
]
}
}
]
获取销售报告
此 API 允许您检索和查看销售报告。
HTTP 请求
GET
/wp-json/wc/v1/reports/sales
curl https://example.com/wp-json/wc/v1/reports/sales?date_min=2016-05-03&date_max=2016-05-04 \
-u consumer_key:consumer_secret
WooCommerce.get("reports/sales", {
date_min: "2016-05-03",
date_max: "2016-05-04"
})
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error.response.data);
});
<?php
$query = [
'date_min' => '2016-05-03',
'date_max' => '2016-05-04'
];
print_r($woocommerce->get('reports/sales', $query));
?>
print(wcapi.get("reports/sales?date_min=2016-05-03&date_max=2016-05-04").json())
query = {
date_min: "2016-05-03",
date_max: "2016-05-04"
}
woocommerce.get("reports/sales", query).parsed_response
JSON 响应示例:
[
{
"total_sales": "14.00",
"net_sales": "4.00",
"average_sales": "2.00",
"total_orders": 3,
"total_items": 6,
"total_tax": "0.00",
"total_shipping": "10.00",
"total_refunds": 0,
"total_discount": "0.00",
"totals_grouped_by": "day",
"totals": {
"2016-05-03": {
"sales": "14.00",
"orders": 3,
"items": 6,
"tax": "0.00",
"shipping": "10.00",
"discount": "0.00",
"customers": 0
},
"2016-05-04": {
"sales": "0.00",
"orders": 0,
"items": 0,
"tax": "0.00",
"shipping": "0.00",
"discount": "0.00",
"customers": 0
}
},
"total_customers": 0,
"_links": {
"about": [
{
"href": "https://example.com/wp-json/wc/v1/reports"
}
]
}
}
]
Sales report properties
| Attribute | Type | Description |
|---|---|---|
total_sales |
string | Gross sales in the period. read-only |
net_sales |
string | Net sales in the period. read-only |
average_sales |
string | Average net daily sales. read-only |
total_orders |
integer | Total of orders placed. read-only |
total_items |
integer | Total of items purchased. read-only |
total_tax |
string | Total charged for taxes. read-only |
total_shipping |
string | Total charged for shipping. read-only |
total_refunds |
number | Total of refunded orders. read-only |
total_discount |
integer | Total of coupons used. read-only |
totals_grouped_by |
string | Group type. read-only |
totals |
array | Totals. read-only |
Available parameters
| Parameter | Type | Description |
|---|---|---|
context |
string | Scope under which the request is made; determines fields present in response. Default is view. Options: view. |
period |
string | Report period. Default is today's date. Options: week, month, last_month and year |
date_min |
string | Return sales for a specific start date, the date need to be in the YYYY-MM-DD format. |
date_max |
string | Return sales for a specific end date, the date need to be in the YYYY-MM-DD format. |
获取热销商品报告
此 API 允许您检索和查看热销商品报告列表。
HTTP 请求
GET
/wp-json/wc/v1/reports/top_sellers
curl https://example.com/wp-json/wc/v1/reports/top_sellers?period=last_month \
-u consumer_key:consumer_secret
WooCommerce.get("reports/top_sellers", {
period: "last_month",
})
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error.response.data);
});
<?php
$query = [
'period' => 'last_month'
];
print_r($woocommerce->get('reports/top_sellers', $query));
?>
print(wcapi.get("reports/top_sellers?period=last_month").json())
query = {
period: "last_month"
}
woocommerce.get("reports/top_sellers", query).parsed_response
JSON 响应示例:
[
{
"title": "Happy Ninja",
"product_id": 37,
"quantity": 1,
"_links": {
"about": [
{
"href": "https://example.com/wp-json/wc/v1/reports"
}
],
"product": [
{
"href": "https://example.com/wp-json/wc/v1/products/37"
}
]
}
},
{
"title": "Woo Album #4",
"product_id": 96,
"quantity": 1,
"_links": {
"about": [
{
"href": "https://example.com/wp-json/wc/v1/reports"
}
],
"product": [
{
"href": "https://example.com/wp-json/wc/v1/products/96"
}
]
}
}
]
Top sellers report properties
| Attribute | Type | Description |
|---|---|---|
title |
string | Product title. read-only |
product_id |
integer | Product ID. read-only |
quantity |
integer | Total number of purchases. read-only |
Available parameters
| Parameter | Type | Description |
|---|---|---|
context |
string | Scope under which the request is made; determines fields present in response. Default is view. Options: view. |
period |
string | Report period. Default is week. Options: week, month, last_month and year |
date_min |
string | Return sales for a specific start date, the date need to be in the YYYY-MM-DD format. |
date_max |
string | Return sales for a specific end date, the date need to be in the YYYY-MM-DD format. |