> For the complete documentation index, see [llms.txt](https://docs.trybit.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.trybit.com/pt/referencia-da-api-v2/statistics.md).

# Estatísticas

O método permite recuperar estatísticas de pagamentos enviando uma solicitação POST.

### O que o método permite fazer

* Retorna estatísticas sobre os estados das faturas para o período especificado.

### Endpoint

<mark style="color:verde;">`POST`</mark> `https://api.trybit.com/v2/invoice/merchant/statistics`

### Cabeçalhos

| Nome                                               | Tipo   | Exemplo                             | Descrição               |
| -------------------------------------------------- | ------ | ----------------------------------- | ----------------------- |
| Autorização<mark style="color:vermelho;">\*</mark> | string | Token eyJ0eXAiOiJK<...>4npi1ksS8tSY | Chave de API do projeto |

### Corpo da solicitação

Parâmetros principais

| Nome                                         | Tipo   | Exemplo    | Descrição                                                                                              |
| -------------------------------------------- | ------ | ---------- | ------------------------------------------------------------------------------------------------------ |
| start<mark style="color:vermelho;">\*</mark> | string | 01.01.2026 | Data no formato `«dd.mm.yyyyy»`                                                                        |
| end<mark style="color:vermelho;">\*</mark>   | string | 31.01.2026 | <p>Data no formato <code>«dd.mm.yyyyy»</code><br><br>Deve ser maior ou igual a <code>start</code>.</p> |

### Exemplos de solicitação

Estes exemplos mostram como enviar uma solicitação para recuperar estatísticas sobre os estados das faturas para o período especificado.

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

```bash
curl -X POST https://api.trybit.com/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.trybit.com/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("Sucesso:", response.json())
else:
    print("Falha:", response.status_code, response.text)
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
fetch('https://api.trybit.com/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('Falha: ' + response.status + ' ' + response.statusText);
    }
})
.then(data => console.log('Sucesso:', data))
.catch(error => console.error('Erro:', error));
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.trybit.com/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 'Erro:' . curl_error($ch);
} else {
    $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($statusCode == 200) {
        echo "Sucesso: " . $response;
    } else {
        echo "Falha: " . $statusCode . " " . $response;
    }
}

curl_close($ch);
?>
```

{% endtab %}
{% endtabs %}

### Exemplos de resposta

Uma solicitação bem-sucedida retorna uma resposta com o status `sucesso` e um `resultado` objeto.

{% tabs %}
{% tab title="200: OK – Estatísticas" %}

```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 %}

### Parâmetros de resposta

O `resultado` objeto contém:

| Nome            | Tipo       | Exemplo                                                                                                                                                                                                                                                                   | Descrição                                        |
| --------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| contagem        | 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>                                  | Objeto contendo valores para o número de faturas |
| 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> | Objeto contendo valores para montantes em USD    |
| total           | int, float | 907 / 214356.22712                                                                                                                                                                                                                                                        | Todas as faturas                                 |
| created         | int, float | 4 / 4.0                                                                                                                                                                                                                                                                   | Faturas com o estado “Criado”                    |
| pago            | int, float | 90 / 629.729137                                                                                                                                                                                                                                                           | Faturas com o estado “Pago”                      |
| pago em excesso | int, float | 8 / 36.82                                                                                                                                                                                                                                                                 | Faturas com o estado “Pagas em excesso”          |
| parcial         | int, float | 6 / 11.4                                                                                                                                                                                                                                                                  | Faturas com o estado “Parcialmente pagas”        |
| cancelado       | int, float | 799 / 213674.277983                                                                                                                                                                                                                                                       | Faturas com o estado “Canceladas”                |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.trybit.com/pt/referencia-da-api-v2/statistics.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
