<html lang="it-it" dir="ltr"><head></head><body># EDD REST API - Statistiche

 La [EDD REST API](https://easydigitaldownloads.com/docs/edd-rest-api-introduction/) può restituire una grande quantità di informazioni statistiche sul tuo negozio utilizzando l'endpoint `/stats/`. La query stats viene utilizzata per recuperare le statistiche di guadagno/vendita dal tuo negozio. Può essere utilizzata per recuperare i guadagni totali per il mese corrente, l'anno scorso, un intervallo di date specifico, ecc., così come le stesse opzioni per le vendite. Può anche essere utilizzata per recuperare le statistiche di guadagno/vendita per uno qualsiasi o tutti i prodotti.

 L'endpoint delle statistiche è:

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

 Nota che la query *stats* richiede il passaggio di un parametro *type*. Ci sono due opzioni di tipo:

- **sales** - Per recuperare le statistiche di vendita.
- **earnings** - Per recuperare le statistiche di guadagno.

 Entrambi i tipi di query *sales* ed *earnings* includono parametri aggiuntivi per le opzioni di data e prodotto:

- **date** - La data per cui recuperare guadagni o vendite. Questo ha tre valori accettati: 
    - **today** - Recupererà le statistiche per il giorno corrente.
    - **yesterday** - Recupererà le statistiche per il giorno precedente.
    - **range** - Recupererà le statistiche per un intervallo di date. 
        - **startdate** - Formato: YYYYMMDD. Esempio: 20120224 = 2012/02/24
        - **enddate** - Formato: YYYYMMDD. Esempio: 20120531 = 2012/02/24
- **product** - utilizzato per recuperare statistiche di vendita o guadagno per un prodotto specifico, o tutti i prodotti. Questa opzione ha due valori accettati: 
    - **\#** - L'ID del prodotto per cui recuperare le statistiche.
    - **all** - Recupera le statistiche per tutti i prodotti. Questa opzione non supporta [l'impaginazione](https://easydigitaldownloads.com/wp-admin/post.php?post=33400&amp;action=edit#paging).

 **Nota**: le opzioni *product* e *date* non possono essere combinate. Puoi usarne solo una o l'altra.

 Una query di base per le statistiche di guadagno si presenta così:

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

 E la risposta è:

```
{
    "earnings": {
        "current_month": 20,
        "last_month": 311.96,
        "totals": 1302.2764
    }
}
```

 Una query di base per le statistiche di vendita si presenta così:

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

 E la risposta è:

```
{
    "sales": {
        "current_month": 1,
        "last_month": 18,
        "totals": 71
    }
}
```

 Se si passa una data come *today* o *yesterday*, la query sarà:

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

 E la risposta:

```
{
    "sales": {
        "today": 1
    }
}
```

 Se si passa un intervallo di date, la query sarà:

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

 E la risposta:

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

 Ogni elemento nell'oggetto *sales* rappresenta il giorno e il valore è l'importo.

 Se si passa il parametro *product*, così

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

 la risposta sarà:

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

 O per un singolo prodotto:

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

 Risposta:

```
{
    "sales": [
        {
            "simple-notices-pro": "48"
        }
    ]
}
```</body></html>