# Metrics API Reference

Source: https://instatus.com/help/api/metrics

## Get all metrics

**Endpoint:**

```bash
GET /v1/:page_id/metrics?page=:page&per_page=:per_page
```

- The default page number is 1.
- The default per_page number is 50 and the maximum is 100 items per page.

**Example response:**

```json
[
  {
    "id": "ckj1qyonq9sdk09819xdg4ehm",
    "name": "Testing",
    "active": true,
    "order": 1,
    "suffix": "ms",
    "data": [
      {
        "timestamp": 1608474985000,
        "value": 355
      },
      {
        "timestamp": 1608475225000,
        "value": 428.25
      },
      {
        "timestamp": 1608475465000,
        "value": 356
      },
      {
        "timestamp": 1608475705000,
        "value": 451.75
      },
      ...
    ]
  },
  ...
]
```

## Get a metric

**Endpoint:**

```bash
GET /v1/:page_id/metrics/:metric_id
```

**Example response:**

```json
{
  "id": "ckj1qyonq9sdk09819xdg4ehm",
  "name": "Testing",
  "active": true,
  "order": 1,
  "suffix": "ms",
  "data": [
    {
      "timestamp": 1608474985000,
      "value": 355
    },
    {
      "timestamp": 1608475225000,
      "value": 428.25
    },
    {
      "timestamp": 1608475465000,
      "value": 356
    },
    {
      "timestamp": 1608475705000,
      "value": 451.75
    },
    ...
  ]
}
```

## Add a metric

**Endpoint:**

```bash
POST /v1/:page_id/metrics
```

```json
{
  "subdomain": "nasa",
  "name": "Response time",
  "suffix": "ms"
}
```

**Example response:**

```json
{
  "id": "ckj1qyonq9sdk09819xdg4ehm",
  "name": "Response time",
  "active": true,
  "order": 1,
  "suffix": "ms",
  "lastDataAt": 1608561235000,
  "data": [
    {
      "timestamp": 1608474985000,
      "value": 355
    },
    {
      "timestamp": 1608475225000,
      "value": 428.25
    },
    {
      "timestamp": 1608475465000,
      "value": 356
    },
    ...
  ]
}
```

## Update a metric

**Endpoint:**

```bash
PUT /v1/:page_id/metrics/:metric_id
```

**Example request:**

```json
{
  "name": "Response time",
  "suffix": "ms"
}
```

**Example response:**

```json
{
  "id": "ckj1qyonq9sdk09819xdg4ehm",
  "name": "Response time",
  "active": true,
  "order": 1,
  "suffix": "ms",
  "lastDataAt": 1608561235000,
  "data": [
    {
      "timestamp": 1608474985000,
      "value": 355
    },
    {
      "timestamp": 1608475225000,
      "value": 428.25
    },
    {
      "timestamp": 1608475465000,
      "value": 356
    },
    ...
  ]
}
```

## Delete a metric

**Endpoint:**

```bash
DELETE /v1/:page_id/metrics/:metric_id
```

### Add a datapoint to a metric

**Endpoint:**

```bash
POST /v1/:page_id/metrics/:metric_id
```

**Request:**

```json
{
  "timestamp": 1608672985000,
  "value": 356
}
```

**Response:**

```json
{
  "id": "ckj395ptx9ha40995ckzv0pz2",
  "value": 356,
  "timestamp": 1608672985000
}
```

## Add multiple datapoints to a metric

**Endpoint:**

```bash
POST /v1/:page_id/metrics/:metric_id/data
```

**Request:**

```json
{
  "data": [
  {
    "timestamp": 1608474985000,
    "value": 355
  },
  {
    "timestamp": 1608475225000,
    "value": 428.25
  },
  {
    "timestamp": 1608475465000,
    "value": 356
  },
  {
    "timestamp": 1608475705000,
    "value": 451.75
  },
  {
    "timestamp": 1608475945000,
    "value": 395
  },
  {
    "timestamp": 1608476185000,
    "value": 375.75
  },
  {
    "timestamp": 1608476425000,
    "value": 380.25
  },
  ...
  ]
}
```

**Response**

```json
[
  {
    "timestamp": 1608474985000,
    "value": 355
  },
  {
    "timestamp": 1608475225000,
    "value": 428.25
  },
  {
    "timestamp": 1608475465000,
    "value": 356
  },
  {
    "timestamp": 1608475705000,
    "value": 451.75
  },
  {
    "timestamp": 1608475945000,
    "value": 395
  },
  {
    "timestamp": 1608476185000,
    "value": 375.75
  },
  {
    "timestamp": 1608476425000,
    "value": 380.25
  }
]
```

## Delete datapoints to a metric

**Endpoint:**

```bash
DELETE /v1/:page_id/metrics/:metric_id/data
```

**Response**

```json
{
  "name": "Response time",
  "site": {
    "id": "ckj1qyonq9sdk09819xdg4ehm",
    "subdomain": "our"
  }
}
```
