> For the complete documentation index, see [llms.txt](https://docs.iotify.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.iotify.io/api/metrics-api.md).

# Metrics API

## Get a list of available metrics

<mark style="color:blue;">`GET`</mark> `nsim.iotify.io/api/datastore/:workspaceId/metric/list`

#### Path Parameters

| Name                                          | Type   | Description                                                          |
| --------------------------------------------- | ------ | -------------------------------------------------------------------- |
| workspaceId<mark style="color:red;">\*</mark> | string | WorkspaceID for the workspace whose metrics list needs to be fetched |

#### Headers

| Name                                           | Type   | Description                                |
| ---------------------------------------------- | ------ | ------------------------------------------ |
| Accept<mark style="color:red;">\*</mark>       | String | application/json                           |
| key<mark style="color:red;">\*</mark>          | String | API token for the account                  |
| domain<mark style="color:red;">\*</mark>       | String | The domain under which your account exists |
| Content-Type<mark style="color:red;">\*</mark> | String | application/json                           |

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

```json
[{
    "key": "Metric_0"
}, {
    "key": "Metric_1"
}, {
    "key": "Metric_2"
}, {
    "key": "Metric_3"
}, {
    "key": "Metric_4"
}]
```

{% endtab %}
{% endtabs %}

{% code overflow="wrap" %}

```javascript
// Example curl command

curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" -H "key:$KEY" -H "domain:nsim.iotify.io" nsim.iotify.io/api/datastore/$WORKSPACEID/metric/list
```

{% endcode %}

## Get the data for a metric

<mark style="color:green;">`POST`</mark> `nsim.iotify.io/api/datastore/:workspaceId/metric/list/:metricKey`

#### Path Parameters

| Name                                          | Type   | Description                                           |
| --------------------------------------------- | ------ | ----------------------------------------------------- |
| metricKey<mark style="color:red;">\*</mark>   | String | The key for the metric                                |
| workspaceId<mark style="color:red;">\*</mark> | String | WorkspaceID for the workspace where the metric exists |

#### Headers

| Name         | Type   | Description                                |
| ------------ | ------ | ------------------------------------------ |
| Accept       | String | application/json                           |
| key          | String | API token for the account                  |
| domain       | String | The domain under which your account exists |
| Content-Type | String | application/json                           |

#### Request Body

| Name                                           | Type   | Description                                                              |
| ---------------------------------------------- | ------ | ------------------------------------------------------------------------ |
| timeInterval<mark style="color:red;">\*</mark> | Number | Metrics aggregated over time interval                                    |
| aggregateBy<mark style="color:red;">\*</mark>  | String | The aggregation function to be used                                      |
| timeUnit<mark style="color:red;">\*</mark>     | String | The unit of time for the time interval                                   |
| entityId                                       | String | The ID for the simulation job (If you want metrics only for a fixed job) |

{% tabs %}
{% tab title="201: Created " %}

```javascript
[
    [1671190292000, 77],
    [1671190302000, 77],
    [1671190312000, 78],
    [1671190322000, 70],
    [1671190332000, 72],
    [1671190342000, 70],
    [1671190352000, 68],
    [1671190362000, 68],
    [1671190372000, 66],
    [1671190382000, 67],
    [1671190392000, 69],
    [1671190402000, 68]
]
```

{% endtab %}
{% endtabs %}

{% code overflow="wrap" %}

```javascript
// Example curl command

curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" -H "key:$KEY" -H "domain:nsim.iotify.io" -d '{"timeInterval":"1","timeUnit":"s","aggregateBy":"AVG","entityId":"fbe7933c-b27e-4397-8214-21a82e2e011b"}' nsim.iotify.io/api/datastore/$WORKSPACEID/metric/$METRICKEY
```

{% endcode %}
