EDD REST API – Stats
The
EDD REST API can return a great deal of statistical information about your store using the /stats/ endpoint. The stats query is used for retrieving earnings/sales stats from your store. It can be used to retrieve total earnings for the current month, last year, a specific date rage, etc, as well as the same options for sales. It can also be used for retrieving earnings / sales stats for any or all products.
The stats endpoint is:
http://example.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&token=5f9432f3ffa5945755ebc66179810d70&type=
Note that the
stats query requires a type parameter to be passed. There are two type options:
- sales – For retrieving sale stats.
- earnings – For retrieving earning stats.
Both
sales and earnings query types include additional parameters for date and product options:
- date – The date to retrieve earnings or sales for. This has three accepted values:
- today – Will retrieve stats for the current day.
- yesterday – Will retrieve stats for the previous day.
- range – Will retrieve stats for a date range.
- startdate – Format: YYYYMMDD. Example: 20120224 = 2012/02/24
- enddate – Format: YYYYMMDD. Example: 20120531 = 2012/02/24
- product – used to retrieve sale or earnings stats for a specific product, or all products. This option has two accepted values:
- # – The product ID to retrieve stats for.
- all – Retrieve stats for all products. This option does not support paging.
Note: the product and date options cannot be combined. You may only use one or the other.
A basic earnings stats query looks like this:
http://example.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&token=5f9432f3ffa5945755ebc66179810d70&type=earnings
And the response is:
{
"earnings": {
"current_month": 20,
"last_month": 311.96,
"totals": 1302.2764
}
}
A basic sales stats query looks like this:
http://yoursite.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&token=5f9432f3ffa5945755ebc66179810d70&type=sales
And the response is:
{
"sales": {
"current_month": 1,
"last_month": 18,
"totals": 71
}
}
If passing a date of
today or yesterday, the query looks like this:
http://yoursite.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&token=5f9432f3ffa5945755ebc66179810d70&type=sales&date=today
And the response:
{
"sales": {
"today": 1
}
}
If passing a date range, the query will be:
http://yoursite.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&token=5f9432f3ffa5945755ebc66179810d70&type=sales&date=range&startdate=20130201&enddate=20130210
And the response:
{
"totals": 12,
"sales": {
"20130201": 0,
"20130202": 0,
"20130203": 0,
"20130204": 0,
"20130205": 0,
"20130206": 1,
"20130207": 0,
"20130208": 0,
"20130209": 11,
"20130210": 0
}
}
Each item in the
sales object represents the day and the value is the amount.
If passing the
product parameter, like so
http://yoursite.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&token=5f9432f3ffa5945755ebc66179810d70&type=sales&product=all
the response will be:
{
"sales": [
{
"test-2": "6"
},
{
"simple-notices-pro": "48"
},
{
"love-it-pro": "13"
},
{
"test-product-2-2": "0"
},
{
"test-product-1-2": "0"
}
]
}
Or for an individual product:
http://yoursite.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&token=5f9432f3ffa5945755ebc66179810d70&type=sales&product=16
Response:
{
"sales": [
{
"simple-notices-pro": "48"
}
]
}