Back to Woocommerce

Reports

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

10.9.0-dev8.7 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/v2/reports
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v2/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/v2/reports/sales"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v2/reports"
        }
      ]
    }
  },
  {
    "slug": "top_sellers",
    "description": "List of top sellers products.",
    "_links": {
      "self": [
        {
          "href": "https://example.com/wp-json/wc/v2/reports/top_sellers"
        }
      ],
      "collection": [
        {
          "href": "https://example.com/wp-json/wc/v2/reports"
        }
      ]
    }
  }
]
</TabItem> </Tabs>

Retrieve sales report

This API lets you retrieve and view a sales report.

http
GET /wp-json/wc/v2/reports/sales
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v2/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/v2/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_refundsnumberTotal 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/v2/reports/top_sellers
<Tabs> <TabItem value="curl" label="cURL">
shell
curl https://example.com/wp-json/wc/v2/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/v2/reports"
        }
      ],
      "product": [
        {
          "href": "https://example.com/wp-json/wc/v2/products/37"
        }
      ]
    }
  },
  {
    "title": "Woo Album #4",
    "product_id": 96,
    "quantity": 1,
    "_links": {
      "about": [
        {
          "href": "https://example.com/wp-json/wc/v2/reports"
        }
      ],
      "product": [
        {
          "href": "https://example.com/wp-json/wc/v2/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.