# Statistics

### What the method allows you to do

* Returns statistics on invoice statuses for the specified period.

### Endpoint

<mark style="color:green;">`POST`</mark> `https://api.cryptocloud.plus/v2/invoice/merchant/statistics`

### Headers

| Name                                            | Type   | Example                             | Description     |
| ----------------------------------------------- | ------ | ----------------------------------- | --------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Token eyJ0eXAiOiJK<...>4npi1ksS8tSY | Project API key |

### Request Body

Key parameters

| Name                                    | Type   | Example    | Description                                                                                                  |
| --------------------------------------- | ------ | ---------- | ------------------------------------------------------------------------------------------------------------ |
| start<mark style="color:red;">\*</mark> | string | 01.01.2026 | Date in format `«dd.mm.yyyyy»`                                                                               |
| end<mark style="color:red;">\*</mark>   | string | 31.01.2026 | <p>Date in format <code>«dd.mm.yyyyy»</code><br><br>Must be greater than or equal to <code>start</code>.</p> |

### Request examples

These examples show how to send a request to retrieve statistics on invoice statuses for the specified period.

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST https://api.cryptocloud.plus/v2/invoice/merchant/statistics \
     -H "Authorization: Token <API KEY>" \
     -H "Content-Type: application/json" \
     -d '{"start":"01.01.2023","end":"31.01.2023"}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.cryptocloud.plus/v2/invoice/merchant/statistics"
headers = {
    "Authorization": "Token <API KEY>"
}
data = {
    "start": "01.01.2023",
    "end": "31.01.2023"
}

response = requests.post(url, headers=headers, json=data)

if response.status_code == 200:
    print("Success:", response.json())
else:
    print("Fail:", response.status_code, response.text)
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
fetch('https://api.cryptocloud.plus/v2/invoice/merchant/statistics', {
    method: 'POST',
    headers: {
        'Authorization': 'Token <API KEY>',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        start: '01.01.2023',
        end: '31.01.2023'
    })
})
.then(response => {
    if (response.ok) {
        return response.json();
    } else {
        throw new Error('Fail: ' + response.status + ' ' + response.statusText);
    }
})
.then(data => console.log('Success:', data))
.catch(error => console.error('Error:', error));
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.cryptocloud.plus/v2/invoice/merchant/statistics");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
    "start" => "01.01.2023",
    "end" => "31.01.2023"
)));

$headers = array(
    "Authorization: Token <API KEY>",
    "Content-Type: application/json"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($statusCode == 200) {
        echo "Success: " . $response;
    } else {
        echo "Fail: " . $statusCode . " " . $response;
    }
}

curl_close($ch);
?>
```

{% endtab %}
{% endtabs %}

### Response examples

A successful request returns a response with the status `success` and a `result` object.

{% tabs %}
{% tab title="200: OK – Statistics" %}

```json
{
    "status": "success",
    "result": {
        "count": {
            "all": 907,
            "created": 4,
            "paid": 90,
            "overpaid": 8,
            "partial": 6,
            "canceled": 799
        },
        "amount": {
            "all": 214356.22712,
            "created": 4.0,
            "paid": 629.729137,
            "overpaid": 36.82,
            "partial": 11.4,
            "canceled": 213674.277983
        }
    }
}
```

{% endtab %}
{% endtabs %}

### Response parameters

The `result` object contains:

| Name     | Type       | Example                                                                                                                                                                                                                                                                   | Description                                         |
| -------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
| count    | dict       | <p>        "count": {</p><p>            "all": 907,</p><p>            "created": 4,</p><p>            "paid": 90,</p><p>            "overpaid": 8,</p><p>            "partial": 6,</p><p>            "canceled": 799</p><p>        }</p>                                  | Object containing values for the number of invoices |
| amount   | dict       | <p>    "amount": {</p><p>            "all": 214356.22712,</p><p>            "created": 4.0,</p><p>            "paid": 629.729137,</p><p>            "overpaid": 36.82,</p><p>            "partial": 11.4,</p><p>            "canceled": 213674.277983</p><p>        }</p> | Object containing values for amounts in USD         |
| all      | int, float | 907 / 214356.22712                                                                                                                                                                                                                                                        | All invoices                                        |
| created  | int, float | 4 / 4.0                                                                                                                                                                                                                                                                   | Invoices with the “Created” status                  |
| paid     | int, float | 90 / 629.729137                                                                                                                                                                                                                                                           | Invoices with the “Paid” status                     |
| overpaid | int, float | 8 / 36.82                                                                                                                                                                                                                                                                 | Invoices with the “Overpaid” status                 |
| partial  | int, float | 6 / 11.4                                                                                                                                                                                                                                                                  | Invoices with the “Partially paid” status           |
| canceled | int, float | 799 / 213674.277983                                                                                                                                                                                                                                                       | Invoices with the “Canceled” status                 |
