## Statistics

The Statistics API returns an ordered array of statistical data. It's usually used to render a table.

[!badge variant="primary" text="GET"] <span style="color:grey">https://msp_domain</span>**/v2/stats/:type**

<p class="header">Header</p>

| Name                                                       | Value                 |
| ---------------------------------------------------------- | --------------------- |
| Authorization <span style="color:orange">*required*</span> | Personal access token |

<p class="header">Path</p>

| Name                                              | Value                                 |
| ------------------------------------------------- | ------------------------------------- |
| type <span style="color:orange">*required*</span> | The type of statistic. Currently the following 3 are supported `topBoxesByBlockedFlows` `topBoxesBySecurityAlarms` `topRegionsByBlockedFlows` |

<p class="header">Query String</p>

| Name  | Value                                 |
| ----- | ------------------------------------- |
| group | Gets statistics for specific group, must be supplied with the ID of a box group. The API returns global statistics by default
| limit | Max number of results being returned. Defaults to `5`

<p class="response">Response</p>

<p class="statusCode"><svg class="green" viewBox="0 0 8 16" preserveAspectRatio="xMidYMid meet"><path d="M0 8c0-2.2 1.8-4 4-4s4 1.8 4 4-1.8 4-4 4-4-1.8-4-4z" fill="currentColor" fill-rule="evenodd"></path></svg>
<span>200 Success</span>

</p>

A JSON array of [Statistics](../data-models/statistics.md/#statistic)

```json
[
    {
        "meta": {
            "gid":"00000000-0000-0000-0000-000000000000",
            "name":"My Gold",
            "model":"gold"
        },
        "value": 20
    },
    {
        "meta": {
            "gid":"00000000-0000-0000-0000-000000000001",
            "name":"My Purple",
            "model":"purple"
        },
        "value": 10
    }
]
```

<p class="statusCode">
<svg viewBox="0 0 8 16" preserveAspectRatio="xMidYMid meet" class="brown"><path d="M0 8c0-2.2 1.8-4 4-4s4 1.8 4 4-1.8 4-4 4-4-1.8-4-4z" fill="currentColor" fill-rule="evenodd"></path></svg>
<span>401 Permission Denied</span>
</p>

<p class="examples">Examples</p>

+++ Node.js
```js
const axios = require('axios');

// Change these three configurations to what you need
const msp_domain = process.env.msp_domain || "mydomain.firewalla.net";
const token = process.env.token || "your_personal_access_token";
const type = process.env.type || "topBoxesByBlockedFlows";
const group = process.env.group || "137";


axios({
    method: 'get',
    url: `https://${msp_domain}/v2/stats/${type}?group=${group}`,
    headers: {
        Authorization: `Token ${token}`,
        "Content-Type": "application/json"
    }
}).then((res) => {
    let data = res.data;
    console.log(data);
})
```
+++ cURL
```bash
curl --request GET  \
--url "https://${msp_domain}/v2/stats/${type}?group=${group}" \
--header "Authorization: Token ${your_personal_access_token}"
```
+++

## Simple Statistics

This API gives a set of simple statistical numbers. Check out [Simple Statistics](../data-models/statistics.md/#simple-statistic) for more details

[!badge variant="primary" text="GET"] <span style="color:grey">https://msp_domain</span>**/v2/stats/simple**

<p class="header">Header</p>

| Name                                                       | Value                 |
| ---------------------------------------------------------- | --------------------- |
| Authorization <span style="color:orange">*required*</span> | Personal access token |

<p class="header">Query String</p>

| Name  | Value             |
| ----- | ----------------- |
| group | Gets statistics for a specific box group, must be supplied with the ID of a box group. The API returns global statistics by default

<p class="response">Response</p>

<p class="statusCode"><svg class="green" viewBox="0 0 8 16" preserveAspectRatio="xMidYMid meet"><path d="M0 8c0-2.2 1.8-4 4-4s4 1.8 4 4-1.8 4-4 4-4-1.8-4-4z" fill="currentColor" fill-rule="evenodd"></path></svg>
<span>200 Success</span>

</p>

A JSON representation of [Simple Statistic](../data-models/statistics.md/#simple-statistic)

```json
{
    "onlineBoxes": 12,
    "offlineBoxes": 4,
    "alarms": 48,
    "rules": 32
}
```

<p class="statusCode">
<svg viewBox="0 0 8 16" preserveAspectRatio="xMidYMid meet" class="brown"><path d="M0 8c0-2.2 1.8-4 4-4s4 1.8 4 4-1.8 4-4 4-4-1.8-4-4z" fill="currentColor" fill-rule="evenodd"></path></svg>
<span>401 Permission Denied</span>
</p>

<p class="examples">Examples</p>

+++ Node.js
```js
const axios = require('axios');

// Change these three configurations to what you need
const msp_domain = process.env.msp_domain || "mydomain.firewalla.net";
const token = process.env.token || "your_personal_access_token";
const group = process.env.group || "137";


axios({
    method: 'get',
    url: `https://${msp_domain}/v2/stats/simple?group=${group}`,
    headers: {
        Authorization: `Token ${token}`,
        "Content-Type": "application/json"
    }
}).then((res) => {
    let data = res.data;
    console.log(data);
})
```
+++ cURL
```bash
curl --request GET  \
--url "https://${msp_domain}/v2/stats/simple?group=${group}" \
--header "Authorization: Token ${your_personal_access_token}"
```
+++
