# EDD REST API - Stats

 The [EDD REST API](https://easydigitaldownloads.com/docs/edd-rest-api-introduction/) 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:

```
https://example.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&amp;token=5f9432f3ffa5945755ebc66179810d70&amp;type=&lt;query type=&quot;&quot;&gt;
&lt;/query&gt;
```

 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](https://easydigitaldownloads.com/wp-admin/post.php?post=33400&amp;action=edit#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:

```
https://example.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&amp;token=5f9432f3ffa5945755ebc66179810d70&amp;type=earnings
```

 And the response is:

```
{
    &quot;earnings&quot;: {
        &quot;current_month&quot;: 20,
        &quot;last_month&quot;: 311.96,
        &quot;totals&quot;: 1302.2764
    }
}
```

 A basic sales stats query looks like this:

```
https://yoursite.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&amp;token=5f9432f3ffa5945755ebc66179810d70&amp;type=sales
```

 And the response is:

```
{
    &quot;sales&quot;: {
        &quot;current_month&quot;: 1,
        &quot;last_month&quot;: 18,
        &quot;totals&quot;: 71
    }
}
```

 If passing a date of *today* or *yesterday*, the query looks like this:

```
https://yoursite.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&amp;token=5f9432f3ffa5945755ebc66179810d70&amp;type=sales&amp;date=today
```

 And the response:

```
{
    &quot;sales&quot;: {
        &quot;today&quot;: 1
    }
}
```

 If passing a date range, the query will be:

```
https://yoursite.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&amp;token=5f9432f3ffa5945755ebc66179810d70&amp;type=sales&amp;date=range&amp;startdate=20130201&amp;enddate=20130210
```

 And the response:

```
{
    &quot;totals&quot;: 12,
    &quot;sales&quot;: {
        &quot;20130201&quot;: 0,
        &quot;20130202&quot;: 0,
        &quot;20130203&quot;: 0,
        &quot;20130204&quot;: 0,
        &quot;20130205&quot;: 0,
        &quot;20130206&quot;: 1,
        &quot;20130207&quot;: 0,
        &quot;20130208&quot;: 0,
        &quot;20130209&quot;: 11,
        &quot;20130210&quot;: 0
    }
}
```

 Each item in the *sales* object represents the day and the value is the amount.

 If passing the *product* parameter, like so

```
https://yoursite.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&amp;token=5f9432f3ffa5945755ebc66179810d70&amp;type=sales&amp;product=all
```

 the response will be:

```
{
    &quot;sales&quot;: [
        {
            &quot;test-2&quot;: &quot;6&quot;
        },
        {
            &quot;simple-notices-pro&quot;: &quot;48&quot;
        },
        {
            &quot;love-it-pro&quot;: &quot;13&quot;
        },
        {
            &quot;test-product-2-2&quot;: &quot;0&quot;
        },
        {
            &quot;test-product-1-2&quot;: &quot;0&quot;
        }
    ]
}
```

 Or for an individual product:

```
https://yoursite.com/edd-api/stats/?key=c281cf0a95be875d9eeb284fb004c938&amp;token=5f9432f3ffa5945755ebc66179810d70&amp;type=sales&amp;product=16
```

 Response:

```
{
    &quot;sales&quot;: [
        {
            &quot;simple-notices-pro&quot;: &quot;48&quot;
        }
    ]
}
```