# Referencia de la API de métricas

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

## Obtener todas las métricas

**Endpoint:**

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

- El número de página por defecto es 1.
- El valor por defecto de per_page es 50 y el máximo es de 100 elementos por página.

**Respuesta de ejemplo:**

```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
      },
      ...
    ]
  },
  ...
]
```

## Obtener una métrica

**Endpoint:**

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

**Respuesta de ejemplo:**

```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
    },
    ...
  ]
}
```

## Añadir una métrica

**Endpoint:**

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

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

**Respuesta de ejemplo:**

```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
    },
    ...
  ]
}
```

## Actualizar una métrica

**Endpoint:**

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

**Petición de ejemplo:**

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

**Respuesta de ejemplo:**

```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
    },
    ...
  ]
}
```

## Eliminar una métrica

**Endpoint:**

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

### Añadir un punto de datos a una métrica

**Endpoint:**

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

**Petición:**

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

**Respuesta:**

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

## Añadir varios puntos de datos a una métrica

**Endpoint:**

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

**Petición:**

```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
  },
  ...
  ]
}
```

**Respuesta**

```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
  }
]
```

## Eliminar puntos de datos de una métrica

**Endpoint:**

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

**Respuesta**

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