woocommerce-rest-api-docs/source/includes/wc-analytics/_reports.md
2024-08-16 14:48:09 +08:00

31 KiB

Analytics Reports

The reports API enables you to view analytics data on products, sales, revenue, orders, and more.

List all the reports endpoints

This API helps you to list all the endpoints regarding reports.

HTTP request

GET
/wp-json/wc-analytics/reports

Example of how to list all the enpoints regarding WC Analytics reports:

curl https://example.com/wp-json/wc-analytics/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.post("reports").parsed_response

JSON response example:

[
    {
        "slug": "performance-indicators",
        "description": "Batch endpoint for getting specific performance indicators from `stats` endpoints.",
        "path": "/wc-analytics/reports/performance-indicators",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/performance-indicators"
                }
            ],
            "report": [
                {
                    "href": "/analytics/performance-indicators"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "revenue/stats",
        "description": "Stats about revenue.",
        "path": "/wc-analytics/reports/revenue/stats",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/revenue/stats"
                }
            ],
            "report": [
                {
                    "href": "/analytics/revenue"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "orders/stats",
        "description": "Stats about orders.",
        "path": "/wc-analytics/reports/orders/stats",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/orders/stats"
                }
            ],
            "report": [
                {
                    "href": "/analytics/orders"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "products",
        "description": "Products detailed reports.",
        "path": "/wc-analytics/reports/products",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/products"
                }
            ],
            "report": [
                {
                    "href": "/analytics/products"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "products/stats",
        "description": "Stats about products.",
        "path": "/wc-analytics/reports/products/stats",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/products/stats"
                }
            ],
            "report": [
                {
                    "href": "/analytics/products"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "variations",
        "description": "Variations detailed reports.",
        "path": "/wc-analytics/reports/variations",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/variations"
                }
            ],
            "report": [
                {
                    "href": "/analytics/variations"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "variations/stats",
        "description": "Stats about variations.",
        "path": "/wc-analytics/reports/variations/stats",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/variations/stats"
                }
            ],
            "report": [
                {
                    "href": "/analytics/variations"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "categories",
        "description": "Product categories detailed reports.",
        "path": "/wc-analytics/reports/categories",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/categories"
                }
            ],
            "report": [
                {
                    "href": "/analytics/categories"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "categories/stats",
        "description": "Stats about product categories.",
        "path": "/wc-analytics/reports/categories/stats",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/categories/stats"
                }
            ],
            "report": [
                {
                    "href": "/analytics/categories"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "coupons",
        "description": "Coupons detailed reports.",
        "path": "/wc-analytics/reports/coupons",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/coupons"
                }
            ],
            "report": [
                {
                    "href": "/analytics/coupons"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "coupons/stats",
        "description": "Stats about coupons.",
        "path": "/wc-analytics/reports/coupons/stats",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/coupons/stats"
                }
            ],
            "report": [
                {
                    "href": "/analytics/coupons"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "taxes",
        "description": "Taxes detailed reports.",
        "path": "/wc-analytics/reports/taxes",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/taxes"
                }
            ],
            "report": [
                {
                    "href": "/analytics/taxes"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "taxes/stats",
        "description": "Stats about taxes.",
        "path": "/wc-analytics/reports/taxes/stats",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/taxes/stats"
                }
            ],
            "report": [
                {
                    "href": "/analytics/taxes"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "downloads",
        "description": "Product downloads detailed reports.",
        "path": "/wc-analytics/reports/downloads",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/downloads"
                }
            ],
            "report": [
                {
                    "href": "/analytics/downloads"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "downloads/files",
        "description": "Product download files detailed reports.",
        "path": "/wc-analytics/reports/downloads/files",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/downloads/files"
                }
            ],
            "report": [
                {
                    "href": "/analytics/downloads/files"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "downloads/stats",
        "description": "Stats about product downloads.",
        "path": "/wc-analytics/reports/downloads/stats",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/downloads/stats"
                }
            ],
            "report": [
                {
                    "href": "/analytics/downloads"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    },
    {
        "slug": "customers",
        "description": "Customers detailed reports.",
        "path": "/wc-analytics/reports/customers",
        "_links": {
            "self": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports/customers"
                }
            ],
            "report": [
                {
                    "href": "/analytics/customers"
                }
            ],
            "collection": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/reports"
                }
            ]
        }
    }
]

Products

This API lets you retrieve and view the product item sales, net revenue, and the corredsponding orders.

Products Reports properties

Attribute Type Description
product_id integer Unique identifier for the resource. read-only
items_sold integer Number of items sold. read-only
net_revenue integer Total Net sales of all items sold. read-only
orders_count integer Number of orders product appeared in. read-only
extended_info object Extended info for the product. See Product Reports - Extended Info properties

Product Reports - Extended Info properties

Attribute Type Description
name string Product name.
price integer Product price.
image string Product image.
permalink string Product link.
category_ids array Product category IDs.
stock_status string Product inventory status.
stock_quantity integer Product inventory quantity.
low_stock_amount integer Product inventory threshold for low stock.
variations array Product variations IDs.
sku string Product SKU.

HTTP request

GET
/wp-json/wc-analytics/reports/products
curl https://example.com/wp-json/wc-analytics/reports/products \
	-u consumer_key:consumer_secret
WooCommerce.get("reports/products")
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php print_r($woocommerce->get('reports/products')); ?>
print(wcapi.get("reports/products").json())
woocommerce.get("reports/products").parsed_response

JSON response example:

[
    {
        "product_id": 62,
        "items_sold": 1,
        "net_revenue": 18,
        "orders_count": 1,
        "extended_info": {},
        "_links": {
            "product": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/products/62"
                }
            ]
        }
    },
    {
        "product_id": 63,
        "items_sold": 1,
        "net_revenue": 55,
        "orders_count": 1,
        "extended_info": {},
        "_links": {
            "product": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/products/63"
                }
            ]
        }
    },
    {
        "product_id": 64,
        "items_sold": 1,
        "net_revenue": 16,
        "orders_count": 1,
        "extended_info": {},
        "_links": {
            "product": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/products/64"
                }
            ]
        }
    },
    {
        "product_id": 79,
        "items_sold": 1,
        "net_revenue": 18,
        "orders_count": 1,
        "extended_info": {},
        "_links": {
            "product": [
                {
                    "href": "https://example.com/wp-json/wc-analytics/products/79"
                }
            ]
        }
    }
]

Available parameters

Parameter Type Description
context string cope under which the request is made; determines fields present in response. Options: view and edit. Default is view.
page integer Current page of the collection. Default is 1.
per_page integer Maximum number of items to be returned in result set. Default is 10.
after string Limit response to resources published after a given ISO8601 compliant date.
before string Limit response to resources published before a given ISO8601 compliant date.
order string Order sort attribute ascending or descending. Options: asc and desc. Default is desc.
orderby string Sort collection by object attribute. Options: date, net_revenue, orders_count, items_sold, product_name, variations, sku. Default is date.
force_cache_refresh boolean Force retrieval of fresh data instead of from the cache.
categories array Limit result to items from the specified categories.
products array Limit result to items with specified product ids.
match string Indicates whether all the conditions should be true for the resulting set, or if any one of them is sufficient. Match affects the following parameters: status_is, status_is_not, product_includes, product_excludes, coupon_includes, coupon_excludes, customer, categorie. Options: all, any. Default is all.
extended_info boolean Add additional piece of info about each product to the report. Default is false.

Products Stats

This API helps you to view all the products.

Products Stats Reports properties

Attribute Type Description
totals object Totals data. See Products Stats Reports - Totals properties read-only
intervals object Reports data grouped by intervals. See Products Stats Reports - Intervals properties read-only

Products Stats Reports - Totals properties

Attribute Type Description
items_sold integer Number of product items sold. read-only
net_revenue integer Net sales. read-only
orders_count integer Number of orders. read-only
segments array Reports data grouped by segment condition. See Products Stats Reports - Segments properties read-only
Products Stats Reports - Segments properties
Attribute Type Description
segment_id integer Segment identificator. read-only
subtotals object Interval subtotals. See Products Stats Reports - Totals properties, but without segments atttribute. read-only

Segments properties example

[
    {
        "segment_id": 123,
        "subtotals": {
            "iitems_sold": 12,
            "net_revenue": 110,
            "orders_count": 3,
        }
    }
]

Products Stats Reports - Intervals properties

Attribute Type Description
interval string Type of interval. read-only
date_start string The date the report start, in the site's timezone. read-only
date_start_gmt string The date the report start, as GMT. read-only
date_end string The date the report end, in the site's timezone. read-only
date_end_gmt string The date the report end, as GMT. read-only
subtotals object Interval subtotals. See Products Stats Reports - Totals properties. read-only

HTTP request

GET
/wp-json/wc-analytics/reports/products/stats
curl https://example.com/wp-json/wc-analytics/reports/products/stats \
	-u consumer_key:consumer_secret
WooCommerce.get("reports/products/stats")
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
<?php print_r($woocommerce->get('reports/products/stats')); ?>
print(wcapi.get("reports/products/stats").json())
woocommerce.get("reports/products/stats").parsed_response

JSON response example:

{
    "totals": {
        "items_sold": 0,
        "net_revenue": 0,
        "orders_count": 0,
        "products_count": 0,
        "variations_count": 0,
        "segments": []
    },
    "intervals": [
        {
            "interval": "2024-33",
            "date_start": "2024-08-12 00:00:00",
            "date_start_gmt": "2024-08-12 00:00:00",
            "date_end": "2024-08-13 08:04:37",
            "date_end_gmt": "2024-08-13 08:04:37",
            "subtotals": {
                "items_sold": 0,
                "net_revenue": 0,
                "orders_count": 0,
                "products_count": 0,
                "variations_count": 0,
                "segments": []
            }
        },
        {
            "interval": "2024-32",
            "date_start": "2024-08-06 08:04:37",
            "date_start_gmt": "2024-08-06 08:04:37",
            "date_end": "2024-08-11 23:59:59",
            "date_end_gmt": "2024-08-11 23:59:59",
            "subtotals": {
                "items_sold": 0,
                "net_revenue": 0,
                "orders_count": 0,
                "products_count": 0,
                "variations_count": 0,
                "segments": []
            }
        }
    ]
}

Available parameters

Parameter Type Description
context string cope under which the request is made; determines fields present in response. Options: view and edit. Default is view.
page integer Current page of the collection. Default is 1.
per_page integer Maximum number of items to be returned in result set. Default is 10.
after string Limit response to resources published after a given ISO8601 compliant date.
before string Limit response to resources published before a given ISO8601 compliant date.
order string Order sort attribute ascending or descending. Options: asc and desc. Default is desc.
orderby string Sort collection by object attribute. Options: date, coupons, refunds, shipping, taxes, net_revenue, orders_count, items_sold. Default is date.
force_cache_refresh boolean Force retrieval of fresh data instead of from the cache.
categories array Limit result to items from the specified categories.
products array Limit result to items with specified product ids.
variations array Limit result to items with specified variations ID.
segmentby string Segment the response by additional constraint. Options: product, category, variation.
fields array Limit stats fields to the specified items.
interval string Time interval to use for buckets in the returned data. Options: hour, day, week, month, quarter, year.