# Statistics

## Get Component usage statistics

<mark style="color:green;">`GET`</mark> `/stats/component-usage`

Get statistics of component usage. Restricted to **admin** users only.

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |

**Query parameters**

| Name          | Type   | Description                                                                                                                                                              |
| ------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| componentType | string | Component/module identifier. The value can be appmixer.utils returning stats for all modules in utils. Or appmixer.utils.controls returning stats only for the controls. |
| stage         | string | `running\|stopped`. Return statistics only for *running* or *stopped* flows.                                                                                             |
| group         | string | `$flowId\|$userId`                                                                                                                                                       |
| count         | any    | If specified, it will return the number of records.                                                                                                                      |
| limit         | number | Number of records returned.                                                                                                                                              |
| offset        | number | For paging.                                                                                                                                                              |
| userId        | string | Filter statistics per specific user.                                                                                                                                     |

**Response**

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

<pre class="language-json"><code class="lang-json"><strong>[
</strong>    {
        "_id": "630743429943ceeab3652244",
        "flowId": "01beae9d-fd61-4782-aa2c-678455908d1b",
        "type": "componentUsage",
        "value1": "appmixer.utils.controls.OnStart",
        "userId": "5df0edcb36a005003a8538fd",
        "value2": "stopped"
    },
    {
        "_id": "634e76729943ceeab3e534e0",
        "flowId": "01c5a412-d0f3-463c-8eb0-d013a63b57b4",
        "type": "componentUsage",
        "value1": "appmixer.utils.controls.OnStart",
        "userId": "583c06311afb7b0016ef120b",
        "value2": "running"
    },
    {
        "_id": "634e76729943ceeab3e534ec",
        "flowId": "01c5a422-d0f3-463c-8eb0-d013a63b57b4",
        "type": "componentUsage",
        "value1": "appmixer.utils.controls.JoinEach",
        "userId": "583c06311afb7b0016ef120b",
        "value2": "stopped"
    },
    {
        "_id": "634e76729943ceeab3e534e6",
        "flowId": "01c5a452-d0f3-463c-8eb0-d013a63b57b4",
        "type": "componentUsage",
        "value1": "appmixer.utils.controls.Each",
        "userId": "583c06311afb7b0016ef120b",
        "value2": "stopped"
    }
]
</code></pre>

{% endtab %}

{% tab title="400" %}

```json
{
  "error": "Invalid request"
}
```

{% endtab %}
{% endtabs %}

#### Examples

GET /stats/component-usage?componentType=appmixer.utils.controls\&group=$userId\&count=true

{% tabs %}
{% tab title="200" %}
Will return the number of users using the `appmixer.utils.controls` module (in at least one flow, stopped or running).

```json
[{"count":19}]
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.appmixer.com/6.0/6.1/api/statistics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
