Back to Woocommerce

Reports

docs/apis/rest-api/v3/reports.mdx

10.9.0-dev19.6 KB
Original Source

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

Reports

The reports API allows you to view all types of reports available.

List all reports

This API lets you retrieve and view a simple list of available reports.

http
GET /wp-json/wc/v3/reports
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v3/reports \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get( 'reports' )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php print_r($woocommerce->get('reports')); ?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("reports").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.get("reports").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
[
	{
		"slug": "sales",
		"description": "List of sales reports.",
		"_links": {
			"self": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports/sales"
				}
			],
			"collection": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports"
				}
			]
		}
	},
	{
		"slug": "top_sellers",
		"description": "List of top sellers products.",
		"_links": {
			"self": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports/top_sellers"
				}
			],
			"collection": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports"
				}
			]
		}
	},
	{
		"slug": "orders/totals",
		"description": "Orders totals.",
		"_links": {
			"self": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports/orders/totals"
				}
			],
			"collection": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports"
				}
			]
		}
	},
	{
		"slug": "products/totals",
		"description": "Products totals.",
		"_links": {
			"self": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports/products/totals"
				}
			],
			"collection": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports"
				}
			]
		}
	},
	{
		"slug": "customers/totals",
		"description": "Customers totals.",
		"_links": {
			"self": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports/customers/totals"
				}
			],
			"collection": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports"
				}
			]
		}
	},
	{
		"slug": "coupons/totals",
		"description": "Coupons totals.",
		"_links": {
			"self": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports/coupons/totals"
				}
			],
			"collection": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports"
				}
			]
		}
	},
	{
		"slug": "reviews/totals",
		"description": "Reviews totals.",
		"_links": {
			"self": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports/reviews/totals"
				}
			],
			"collection": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports"
				}
			]
		}
	},
	{
		"slug": "categories/totals",
		"description": "Categories totals.",
		"_links": {
			"self": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports/categories/totals"
				}
			],
			"collection": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports"
				}
			]
		}
	},
	{
		"slug": "tags/totals",
		"description": "Tags totals.",
		"_links": {
			"self": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports/tags/totals"
				}
			],
			"collection": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports"
				}
			]
		}
	},
	{
		"slug": "attributes/totals",
		"description": "Attributes totals.",
		"_links": {
			"self": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports/attributes/totals"
				}
			],
			"collection": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports"
				}
			]
		}
	}
]
</TabItem> </Tabs>

Retrieve sales report

This API lets you retrieve and view a sales report.

http
GET /wp-json/wc/v3/reports/sales
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v3/reports/sales?date_min=2016-05-03&date_max=2016-05-04 \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
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 );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
$query = [
    'date_min' => '2016-05-03',
    'date_max' => '2016-05-04'
];

print_r($woocommerce->get('reports/sales', $query));
?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("reports/sales?date_min=2016-05-03&date_max=2016-05-04").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
query = {
  date_min: "2016-05-03",
  date_max: "2016-05-04"
}

woocommerce.get("reports/sales", query).parsed_response
</TabItem> <TabItem value="response" label="JSON 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/v3/reports"
				}
			]
		}
	}
]
</TabItem> </Tabs>

Sales report properties

AttributeTypeDescription
total_salesstringGross sales in the period. READ-ONLY
net_salesstringNet sales in the period. READ-ONLY
average_salesstringAverage net daily sales. READ-ONLY
total_ordersintegerTotal of orders placed. READ-ONLY
total_itemsintegerTotal of items purchased. READ-ONLY
total_taxstringTotal charged for taxes. READ-ONLY
total_shippingstringTotal charged for shipping. READ-ONLY
total_refundsintegerTotal of refunded orders. READ-ONLY
total_discountintegerTotal of coupons used. READ-ONLY
totals_grouped_bystringGroup type. READ-ONLY
totalsarrayTotals. READ-ONLY

Available parameters

ParameterTypeDescription
contextstringScope under which the request is made; determines fields present in response. Default is view. Options: view.
periodstringReport period. Default is today's date. Options: week, month, last_month and year
date_minstringReturn sales for a specific start date, the date need to be in the YYYY-MM-DD format.
date_maxstringReturn sales for a specific end date, the date need to be in the YYYY-MM-DD format.

Retrieve top sellers report

This API lets you retrieve and view a list of top sellers report.

http
GET /wp-json/wc/v3/reports/top_sellers
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v3/reports/top_sellers?period=last_month \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get( 'reports/top_sellers', {
	period: 'last_month',
} )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
$query = [
    'period' => 'last_month'
];

print_r($woocommerce->get('reports/top_sellers', $query));
?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("reports/top_sellers?period=last_month").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
query = {
  period: "last_month"
}

woocommerce.get("reports/top_sellers", query).parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
[
	{
		"title": "Happy Ninja",
		"product_id": 37,
		"quantity": 1,
		"_links": {
			"about": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports"
				}
			],
			"product": [
				{
					"href": "https://example.com/wp-json/wc/v3/products/37"
				}
			]
		}
	},
	{
		"title": "Woo Album #4",
		"product_id": 96,
		"quantity": 1,
		"_links": {
			"about": [
				{
					"href": "https://example.com/wp-json/wc/v3/reports"
				}
			],
			"product": [
				{
					"href": "https://example.com/wp-json/wc/v3/products/96"
				}
			]
		}
	}
]
</TabItem> </Tabs>

Top sellers report properties

AttributeTypeDescription
titlestringProduct title. READ-ONLY
product_idintegerProduct ID. READ-ONLY
quantityintegerTotal number of purchases. READ-ONLY

Available parameters

ParameterTypeDescription
contextstringScope under which the request is made; determines fields present in response. Default is view. Options: view.
periodstringReport period. Default is week. Options: week, month, last_month and year
date_minstringReturn sales for a specific start date, the date need to be in the YYYY-MM-DD format.
date_maxstringReturn sales for a specific end date, the date need to be in the YYYY-MM-DD format.

Retrieve coupons totals

This API lets you retrieve and view coupons totals report.

http
GET /wp-json/wc/v3/reports/coupons/totals
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v3/reports/coupons/totals \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get( 'reports/coupons/totals' )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
print_r($woocommerce->get('reports/coupons/totals'));
?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("reports/coupons/totals").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.get("reports/coupons/totals").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
[
	{
		"slug": "percent",
		"name": "Percentage discount",
		"total": 2
	},
	{
		"slug": "fixed_cart",
		"name": "Fixed cart discount",
		"total": 1
	},
	{
		"slug": "fixed_product",
		"name": "Fixed product discount",
		"total": 1
	}
]
</TabItem> </Tabs>

Coupons totals properties

AttributeTypeDescription
slugstringAn alphanumeric identifier for the resource. READ-ONLY
namestringCoupon type name. READ-ONLY
totalstringAmount of coupons. READ-ONLY

Retrieve customers totals

This API lets you retrieve and view customers totals report.

http
GET /wp-json/wc/v3/reports/customers/totals
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v3/reports/customers/totals \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get( 'reports/customers/totals' )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
print_r($woocommerce->get('reports/customers/totals'));
?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("reports/customers/totals").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.get("reports/customers/totals").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
[
	{
		"slug": "paying",
		"name": "Paying customer",
		"total": 2
	},
	{
		"slug": "non_paying",
		"name": "Non-paying customer",
		"total": 1
	}
]
</TabItem> </Tabs>

Customers totals properties

AttributeTypeDescription
slugstringAn alphanumeric identifier for the resource. READ-ONLY
namestringCustomer type name. READ-ONLY
totalstringAmount of customers. READ-ONLY

Retrieve orders totals

This API lets you retrieve and view orders totals report.

http
GET /wp-json/wc/v3/reports/orders/totals
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v3/reports/orders/totals \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get( 'reports/orders/totals' )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
print_r($woocommerce->get('reports/orders/totals'));
?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("reports/orders/totals").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.get("reports/orders/totals").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
[
	{
		"slug": "pending",
		"name": "Pending payment",
		"total": 7
	},
	{
		"slug": "processing",
		"name": "Processing",
		"total": 2
	},
	{
		"slug": "on-hold",
		"name": "On hold",
		"total": 1
	},
	{
		"slug": "completed",
		"name": "Completed",
		"total": 3
	},
	{
		"slug": "cancelled",
		"name": "Cancelled",
		"total": 0
	},
	{
		"slug": "refunded",
		"name": "Refunded",
		"total": 0
	},
	{
		"slug": "failed",
		"name": "Failed",
		"total": 0
	}
]
</TabItem> </Tabs>

Orders totals properties

AttributeTypeDescription
slugstringAn alphanumeric identifier for the resource. READ-ONLY
namestringOrders status name. READ-ONLY
totalstringAmount of orders. READ-ONLY

Retrieve products totals

This API lets you retrieve and view products totals report.

http
GET /wp-json/wc/v3/reports/products/totals
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v3/reports/products/totals \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get( 'reports/products/totals' )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
print_r($woocommerce->get('reports/products/totals'));
?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("reports/products/totals").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.get("reports/products/totals").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
[
	{
		"slug": "external",
		"name": "External/Affiliate product",
		"total": 1
	},
	{
		"slug": "grouped",
		"name": "Grouped product",
		"total": 1
	},
	{
		"slug": "simple",
		"name": "Simple product",
		"total": 21
	},
	{
		"slug": "variable",
		"name": "Variable product",
		"total": 3
	}
]
</TabItem> </Tabs>

Products totals properties

AttributeTypeDescription
slugstringAn alphanumeric identifier for the resource. READ-ONLY
namestringProduct type name. READ-ONLY
totalstringAmount of products. READ-ONLY

Retrieve reviews totals

This API lets you retrieve and view reviews totals report.

http
GET /wp-json/wc/v3/reports/reviews/totals
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v3/reports/reviews/totals \
	-u consumer_key:consumer_secret
</TabItem> <TabItem value="js" label="JavaScript">
javascript
WooCommerce.get( 'reports/reviews/totals' )
	.then( ( response ) => {
		console.log( response.data );
	} )
	.catch( ( error ) => {
		console.log( error.response.data );
	} );
</TabItem> <TabItem value="php" label="PHP">
php
<?php
print_r($woocommerce->get('reports/reviews/totals'));
?>
</TabItem> <TabItem value="python" label="Python">
python
print(wcapi.get("reports/reviews/totals").json())
</TabItem> <TabItem value="ruby" label="Ruby">
ruby
woocommerce.get("reports/reviews/totals").parsed_response
</TabItem> <TabItem value="response" label="JSON Response">
json
[
	{
		"slug": "rated_1_out_of_5",
		"name": "Rated 1 out of 5",
		"total": 1
	},
	{
		"slug": "rated_2_out_of_5",
		"name": "Rated 2 out of 5",
		"total": 0
	},
	{
		"slug": "rated_3_out_of_5",
		"name": "Rated 3 out of 5",
		"total": 3
	},
	{
		"slug": "rated_4_out_of_5",
		"name": "Rated 4 out of 5",
		"total": 0
	},
	{
		"slug": "rated_5_out_of_5",
		"name": "Rated 5 out of 5",
		"total": 4
	}
]
</TabItem> </Tabs>

Reviews totals properties

AttributeTypeDescription
slugstringAn alphanumeric identifier for the resource. READ-ONLY
namestringReview type name. READ-ONLY
totalstringAmount of reviews. READ-ONLY