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


---

# 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.iotify.io/api/metrics-api.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.
