# Metric sources

The sources that send custom metrics: their tokens, their settings and the tags they apply.

Its operations need the scopes `custom_metrics.edit`, `custom_metrics.view` or `custom_metrics.delete`.

**Endpoints**

- `POST/v1/metric-sources`
- `PUT/v1/metric-sources/{metric_source_uuid}`
- `GET/v1/metric-sources/{metric_source_uuid}`
- `GET/v1/metric-sources`
- `DELETE/v1/metric-sources/{metric_source_uuid}`
- `POST/v1/metric-sources/{metric_source_uuid}/preview-tag-changes`
- `POST/v1/metric-sources/{metric_source_uuid}/revoke-token`
- `POST/v1/metric-sources/{metric_source_uuid}/rotate-token`
- `GET/v1/metric-sources/{metric_source_uuid}/series`
- `GET/v1/metric-sources/{metric_source_uuid}/summary`

## The Metric source object

### Attributes

- `uuid` (string): The source’s uuid.
- `name` (string): The source’s name.
- `slug` (string): The source’s slug, its identifier within the organisation.
- `description` (string or null): The source’s description; null for none.
- `source_type` (string): The source’s type: `custom_source`; an open set.
- `health_status` (string): One of `unknown`, `healthy`, `warning`, `critical`.
- `last_received_at` (integer or null): Epoch milliseconds. When a point last arrived; null if none ever did. An instant: epoch milliseconds, UTC.
- `active` (boolean): Whether the source is switched on.
- `has_ingest_token` (boolean): Whether a usable ingest token exists: a source created and not yet given one, or whose token was revoked, accepts no pushes.
- `ingest_token_last_four` (string or null): The last four characters of the token; never the token.
- `ingest_token_created_at` (integer or null): Epoch milliseconds. When the ingest token was minted; null if none was. An instant: epoch milliseconds, UTC.
- `ingest_token_revoked_at` (integer or null): Epoch milliseconds. When the ingest token was revoked; null otherwise. An instant: epoch milliseconds, UTC.
- `custom_metrics_count` (integer): How many metrics the source owns.
- `max_requests_per_minute` (integer): The request limit in force: the source’s own, else the organisation’s.
- `created_at` (integer or null): Epoch milliseconds. When the source was created. An instant: epoch milliseconds, UTC.
- `tags` (array of objects): The source’s own tags.
  - `uuid` (string): The tag’s uuid.
  - `name` (string): The tag’s name.
- `linked_servers` (array of objects or null): The servers the source’s metrics are linked to directly; null without `servers.view`, the count kept.
  - `uuid` (string): The server’s uuid.
  - `name` (string): The server’s name.
- `linked_servers_count` (integer): How many servers the source’s metrics are linked to directly; given even when `linked_servers` is null.
- `linked_server_all_tags` (array of objects): Servers must carry ALL of these tags.
  - `uuid` (string): The tag’s uuid.
  - `name` (string): The tag’s name.
  - `group` (string or null): The name of the tag’s group; null for a tag in no group.
- `linked_server_any_tags` (array of objects): Servers must carry ANY of these tags.
  - `uuid` (string): The tag’s uuid.
  - `name` (string): The tag’s name.
  - `group` (string or null): The name of the tag’s group; null for a tag in no group.
- `shown_on_servers_count` (integer): How many servers the source’s metrics are shown on.
- `shown_on_servers` (array of objects or null): The first servers they are shown on; null without `servers.view`.
  - `uuid` (string): The server’s uuid.
  - `name` (string): The server’s name.
- `shown_metrics_count` (integer): How many of the source’s metrics are shown (approved and switched on).

**The Metric source object**

```json
{
  "uuid": "75666699-b77d-4631-b576-041e8102a55b",
  "name": "example",
  "slug": "example",
  "description": "example",
  "source_type": "example",
  "health_status": "example",
  "last_received_at": 1794214800000,
  "active": true,
  "has_ingest_token": true,
  "ingest_token_last_four": "example",
  "ingest_token_created_at": 1794214800000,
  "ingest_token_revoked_at": 1794214800000,
  "custom_metrics_count": 1,
  "max_requests_per_minute": 1,
  "created_at": 1794214800000,
  "tags": [
    {
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "name": "example"
    }
  ],
  "linked_servers": [
    {
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "name": "example"
    }
  ],
  "linked_servers_count": 1,
  "linked_server_all_tags": [
    {
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "name": "example",
      "group": "example"
    }
  ],
  "linked_server_any_tags": [
    {
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "name": "example",
      "group": "example"
    }
  ],
  "shown_on_servers_count": 1,
  "shown_on_servers": [
    {
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "name": "example"
    }
  ],
  "shown_metrics_count": 1
}
```

## Create a metric source

POST/v1/metric-sources

Creates a metric source with no ingest token; mint one with the rotate-token operation. The slug defaults to a slug of the name and cannot be changed afterwards. The call is refused when the plan does not allow it.

Needs the scope `custom_metrics.edit`.

### Headers

- `Idempotency-Key` (string): Any text of 1 to 255 visible ASCII characters. A repeat of the same request within 24 hours returns the first answer without running again (the response carries `Idempotent-Replayed: true`); the same key on a different request is refused 422 `invalid_request`.

### Body parameters

- `name` (string, required): The source’s display name.
- `slug` (string or null): The source’s slug, a lowercase identifier of letters, digits, `.`, `_` and `-` up to 100 characters; defaults to a slug of the name and cannot be changed afterwards.
- `description` (string or null): A description of the source, up to 2000 characters; null for none.
- `source_type` (string or null): The source’s type: `custom_source`, the one type that can be created. Values:`custom_source`(an open set: new values may be added)
- `active` (boolean or null): Whether the source is switched on.
- `tag_uuids` (array of strings): The uuids of the tags to put on the source, at most 100; null is refused.

### Returns

`201 Created`:

The created metric source.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**POST /v1/metric-sources**

curl:

```bash
curl -X POST https://rest.watchtower15.com/v1/metric-sources \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "name": "example"
  }'
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

$metricSource = $wt15->metricSources->create(['name' => 'example']);
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

const result = await wt15.metricSources.create({ name: 'example' });
```

Python:

```python
client = Client.from_environment()

result = client.metric_sources.create(name='example')
```

**Response (201 Created)**

```json
{
  "data": {
    "uuid": "75666699-b77d-4631-b576-041e8102a55b",
    "name": "example",
    "slug": "example",
    "description": "example",
    "source_type": "example",
    "health_status": "example",
    "last_received_at": 1794214800000,
    "active": true,
    "has_ingest_token": true,
    "ingest_token_last_four": "example",
    "ingest_token_created_at": 1794214800000,
    "ingest_token_revoked_at": 1794214800000,
    "custom_metrics_count": 1,
    "max_requests_per_minute": 1,
    "created_at": 1794214800000,
    "tags": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      }
    ],
    "linked_servers": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      }
    ],
    "linked_servers_count": 1,
    "linked_server_all_tags": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "group": "example"
      }
    ],
    "linked_server_any_tags": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "group": "example"
      }
    ],
    "shown_on_servers_count": 1,
    "shown_on_servers": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      }
    ],
    "shown_metrics_count": 1
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (402 Payment Required)**

The organisation's payment gate blocks the action: `payment_required` (no payment method) or `invoice_overdue`. Nothing is billed and nothing is started.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/payment_required/",
  "title": "Payment required",
  "status": 402,
  "code": "payment_required",
  "detail": "A payment method must be set before adding resources for monitoring.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the custom_metrics.edit scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid; `errors` names the parameters.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## Update a metric source

PUT/v1/metric-sources/{metric\_source\_uuid}

Changes the fields sent: name, description, request limit, whether it is switched on, tags and linked servers. Tags can also be applied to the source’s metrics with `apply_tags_to_metrics`. A request limit equal to the one in force is not stored, so the source keeps following the organisation’s.

Needs the scope `custom_metrics.edit`.

### Headers

- `Idempotency-Key` (string): Any text of 1 to 255 visible ASCII characters. A repeat of the same request within 24 hours returns the first answer without running again (the response carries `Idempotent-Replayed: true`); the same key on a different request is refused 422 `invalid_request`.

### Path parameters

- `metric_source_uuid` (string (uuid), required): The uuid of the metric source in the path.

### Body parameters

- `name` (string or null): The source’s display name.
- `description` (string or null): A description of the source, up to 2000 characters; null for none.
- `max_requests_per_minute` (integer or null): The source’s own limit of ingest requests a minute, from 1 to 100000; a value equal to the limit in force is not stored, so the source keeps following the organisation’s.
- `active` (boolean or null): Whether the source is switched on.
- `tag_uuids` (array of strings): The uuids of the tags to put on the source, at most 100; required when `apply_tags_to_metrics` is true or `tags_before_uuids` is sent, and an empty list clears them.
- `apply_tags_to_metrics` (boolean or null): Whether the tag change is also applied to the source’s metrics; when true, `tag_uuids` and `tags_before_uuids` are required.
- `tags_before_uuids` (array of strings): The uuids of the tags the source carried when the change was prepared, at most 100; required when `apply_tags_to_metrics` is true, and used to detect that its tags have changed since.
- `linked_server_uuids` (array of strings or null): The uuids of the servers the source’s metrics are shown on, at most 100; an empty list clears them and omitting the key keeps them.
- `linked_server_all_tag_uuids` (array of strings or null): The uuids of server tags a server must ALL carry for the source’s metrics to be shown on it, at most 20; an empty list clears them and omitting the key keeps them.
- `linked_server_any_tag_uuids` (array of strings or null): The uuids of server tags a server must carry at least ONE of for the source’s metrics to be shown on it, at most 20; an empty list clears them and omitting the key keeps them.

### Returns

`200 OK`:

The metric source after the update.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**PUT /v1/metric-sources/{metric_source_uuid}**

curl:

```bash
curl -X PUT https://rest.watchtower15.com/v1/metric-sources/03eb8c34-ff18-4b02-987d-6231f5dcdb38 \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

$metricSource = $wt15->metricSources->update('03eb8c34-ff18-4b02-987d-6231f5dcdb38');
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

const result = await wt15.metricSources.update('03eb8c34-ff18-4b02-987d-6231f5dcdb38');
```

Python:

```python
client = Client.from_environment()

result = client.metric_sources.update('03eb8c34-ff18-4b02-987d-6231f5dcdb38')
```

**Response (200 OK)**

```json
{
  "data": {
    "uuid": "75666699-b77d-4631-b576-041e8102a55b",
    "name": "example",
    "slug": "example",
    "description": "example",
    "source_type": "example",
    "health_status": "example",
    "last_received_at": 1794214800000,
    "active": true,
    "has_ingest_token": true,
    "ingest_token_last_four": "example",
    "ingest_token_created_at": 1794214800000,
    "ingest_token_revoked_at": 1794214800000,
    "custom_metrics_count": 1,
    "max_requests_per_minute": 1,
    "created_at": 1794214800000,
    "tags": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      }
    ],
    "linked_servers": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      }
    ],
    "linked_servers_count": 1,
    "linked_server_all_tags": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "group": "example"
      }
    ],
    "linked_server_any_tags": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "group": "example"
      }
    ],
    "shown_on_servers_count": 1,
    "shown_on_servers": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      }
    ],
    "shown_metrics_count": 1
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the custom_metrics.edit scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid; `errors` names the parameters.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## Get a metric source

GET/v1/metric-sources/{metric\_source\_uuid}

Returns one metric source with its tags, linked servers and the servers its metrics are shown on. The token is never returned. Server names are given only to a key holding `servers.view`; without it they are null and the counts are kept.

Needs the scope `custom_metrics.view`.

### Path parameters

- `metric_source_uuid` (string (uuid), required): The uuid of the metric source in the path.

### Returns

`200 OK`:

The metric source.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**GET /v1/metric-sources/{metric_source_uuid}**

curl:

```bash
curl https://rest.watchtower15.com/v1/metric-sources/03eb8c34-ff18-4b02-987d-6231f5dcdb38 \
  -H "Authorization: Bearer $WT15_API_KEY"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

$metricSource = $wt15->metricSources->view('03eb8c34-ff18-4b02-987d-6231f5dcdb38');
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

const result = await wt15.metricSources.view('03eb8c34-ff18-4b02-987d-6231f5dcdb38');
```

Python:

```python
client = Client.from_environment()

result = client.metric_sources.view('03eb8c34-ff18-4b02-987d-6231f5dcdb38')
```

**Response (200 OK)**

```json
{
  "data": {
    "uuid": "75666699-b77d-4631-b576-041e8102a55b",
    "name": "example",
    "slug": "example",
    "description": "example",
    "source_type": "example",
    "health_status": "example",
    "last_received_at": 1794214800000,
    "active": true,
    "has_ingest_token": true,
    "ingest_token_last_four": "example",
    "ingest_token_created_at": 1794214800000,
    "ingest_token_revoked_at": 1794214800000,
    "custom_metrics_count": 1,
    "max_requests_per_minute": 1,
    "created_at": 1794214800000,
    "tags": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      }
    ],
    "linked_servers": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      }
    ],
    "linked_servers_count": 1,
    "linked_server_all_tags": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "group": "example"
      }
    ],
    "linked_server_any_tags": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "group": "example"
      }
    ],
    "shown_on_servers_count": 1,
    "shown_on_servers": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      }
    ],
    "shown_metrics_count": 1
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the custom_metrics.view scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid (`invalid_request`; `errors` names the parameters).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## List metric sources

GET/v1/metric-sources

Returns the organisation’s metric sources. A source’s token is never returned, only whether one is set and its last four characters. Pages by `page` and `per_page` (`limit` is the same as `per_page`); every page carries `current_page`, `per_page`, `last_page` and `total`.

Needs the scope `custom_metrics.view`.

### Query parameters

- `limit` (integer or null): The same as `per_page`, kept for existing clients.
- `include_total` (string or null): Ignored: `total` is always present. Values:`true``false``1``0`(an open set: new values may be added)
- `per_page` (integer or null): The page size, from 1 to 100.
- `page` (integer or null): The page to read, from 1; 1 when omitted. A page past the last answers no rows.

### Returns

`200 OK`:

One page of the organisation’s metric sources.

Each item of the page:

- `uuid` (string): The source’s uuid.
- `name` (string): The source’s name.
- `slug` (string): The source’s slug, its identifier within the organisation.
- `description` (string or null): The source’s description; null for none.
- `source_type` (string): The source’s type: `custom_source`; an open set.
- `health_status` (string): One of `unknown`, `healthy`, `warning`, `critical`.
- `last_received_at` (integer or null): Epoch milliseconds. When a point last arrived; null if none ever did. An instant: epoch milliseconds, UTC.
- `active` (boolean): Whether the source is switched on.
- `has_ingest_token` (boolean): Whether a usable ingest token exists: a source created and not yet given one, or whose token was revoked, accepts no pushes.
- `ingest_token_last_four` (string or null): The last four characters of the token; never the token.
- `custom_metrics_count` (integer): How many metrics the source owns.
- `tags` (array of objects): The source’s own tags.
  - `uuid` (string): The tag’s uuid.
  - `name` (string): The tag’s name.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**GET /v1/metric-sources**

curl:

```bash
curl https://rest.watchtower15.com/v1/metric-sources \
  -H "Authorization: Bearer $WT15_API_KEY"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

foreach ($wt15->metricSources->list()->autoPaging() as $metricSource) { echo $metricSource->uuid, "\n"; }
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

for await (const item of wt15.metricSources.list()) {
  console.log(item.uuid);
}
```

Python:

```python
client = Client.from_environment()

for item in client.metric_sources.list():
    print(item.uuid)
```

**Response (200 OK)**

```json
{
  "data": [
    {
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "name": "example",
      "slug": "example",
      "description": "example",
      "source_type": "example",
      "health_status": "example",
      "last_received_at": 1794214800000,
      "active": true,
      "has_ingest_token": true,
      "ingest_token_last_four": "example",
      "custom_metrics_count": 1,
      "tags": [
        {
          "uuid": "75666699-b77d-4631-b576-041e8102a55b",
          "name": "example"
        }
      ]
    }
  ],
  "current_page": 1,
  "per_page": 1,
  "last_page": 1,
  "total": 1
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the custom_metrics.view scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid (`invalid_request`; `errors` names the parameters).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## Delete a metric source

DELETE/v1/metric-sources/{metric\_source\_uuid}

Deletes the metric source. The answer has no body.

Needs the scope `custom_metrics.delete`.

### Headers

- `Idempotency-Key` (string): Any text of 1 to 255 visible ASCII characters. A repeat of the same request within 24 hours returns the first answer without running again (the response carries `Idempotent-Replayed: true`); the same key on a different request is refused 422 `invalid_request`.

### Path parameters

- `metric_source_uuid` (string (uuid), required): The uuid of the metric source in the path.

### Returns

`204 No Content`:

The metric source was deleted; there is no body.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**DELETE /v1/metric-sources/{metric_source_uuid}**

curl:

```bash
curl -X DELETE https://rest.watchtower15.com/v1/metric-sources/03eb8c34-ff18-4b02-987d-6231f5dcdb38 \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

$wt15->metricSources->delete('03eb8c34-ff18-4b02-987d-6231f5dcdb38');
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

await wt15.metricSources.delete('03eb8c34-ff18-4b02-987d-6231f5dcdb38');
```

Python:

```python
client = Client.from_environment()

client.metric_sources.delete('03eb8c34-ff18-4b02-987d-6231f5dcdb38')
```

**Response (204 No Content)**

```http
HTTP/1.1 204 No Content
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the custom_metrics.delete scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid; `errors` names the parameters.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## Preview a metric source's tag changes

POST/v1/metric-sources/{metric\_source\_uuid}/preview-tag-changes

Shows what replacing the source’s tags with `tag_uuids` would do to its metrics: how many would change, each tag added or removed with its counts, and the first metrics that would change. Nothing is written. When `tags_before_uuids` is sent and the source’s tags are no longer those, the call is refused.

Needs the scope `custom_metrics.edit`.

### Headers

- `Idempotency-Key` (string): Any text of 1 to 255 visible ASCII characters. A repeat of the same request within 24 hours returns the first answer without running again (the response carries `Idempotent-Replayed: true`); the same key on a different request is refused 422 `invalid_request`.

### Path parameters

- `metric_source_uuid` (string (uuid), required): The uuid of the metric source in the path.

### Body parameters

- `tag_uuids` (array of strings, required): The uuids of the tags the source would carry after the change, at most 100; required, and an empty list means no tags.
- `tags_before_uuids` (array of strings): The uuids of the tags the source carried when the change was prepared, at most 100; used to detect that its tags have changed since.

### Returns

`200 OK`:

The effect the tag change would have on the source’s metrics.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**POST /v1/metric-sources/{metric_source_uuid}/preview-tag-changes**

curl:

```bash
curl -X POST https://rest.watchtower15.com/v1/metric-sources/03eb8c34-ff18-4b02-987d-6231f5dcdb38/preview-tag-changes \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "tag_uuids": [
      "a032a959-856e-4f5c-ac03-081e9fe87bdc"
    ]
  }'
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

$result = $wt15->metricSources->previewTagChanges('03eb8c34-ff18-4b02-987d-6231f5dcdb38', ['tag_uuids' => ['a032a959-856e-4f5c-ac03-081e9fe87bdc']]);
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

const result = await wt15.metricSources.previewTagChanges('03eb8c34-ff18-4b02-987d-6231f5dcdb38', { tag_uuids: ['a032a959-856e-4f5c-ac03-081e9fe87bdc'] });
```

Python:

```python
client = Client.from_environment()

result = client.metric_sources.preview_tag_changes('03eb8c34-ff18-4b02-987d-6231f5dcdb38', tag_uuids=['a032a959-856e-4f5c-ac03-081e9fe87bdc'])
```

**Response (200 OK)**

```json
{
  "data": {
    "metrics_count": 1,
    "metrics_changing": 1,
    "added": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "group": "example",
        "metrics_gaining": 1,
        "metrics_already": 1
      }
    ],
    "removed": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "group": "example",
        "metrics_losing": 1,
        "metrics_without": 1
      }
    ],
    "metrics": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "metric_key": "example",
        "adds": [
          "example"
        ],
        "removes": [
          "example"
        ]
      }
    ]
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the custom_metrics.edit scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid; `errors` names the parameters.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## Revoke a metric source's token

POST/v1/metric-sources/{metric\_source\_uuid}/revoke-token

Revokes the source’s ingest token, so the source accepts no pushes until a new token is minted.

Needs the scope `custom_metrics.delete`.

### Headers

- `Idempotency-Key` (string): Any text of 1 to 255 visible ASCII characters. A repeat of the same request within 24 hours returns the first answer without running again (the response carries `Idempotent-Replayed: true`); the same key on a different request is refused 422 `invalid_request`.

### Path parameters

- `metric_source_uuid` (string (uuid), required): The uuid of the metric source in the path.

### Returns

`200 OK`:

The metric source after its token was revoked.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**POST /v1/metric-sources/{metric_source_uuid}/revoke-token**

curl:

```bash
curl -X POST https://rest.watchtower15.com/v1/metric-sources/03eb8c34-ff18-4b02-987d-6231f5dcdb38/revoke-token \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

$result = $wt15->metricSources->revokeToken('03eb8c34-ff18-4b02-987d-6231f5dcdb38');
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

const result = await wt15.metricSources.revokeToken('03eb8c34-ff18-4b02-987d-6231f5dcdb38');
```

Python:

```python
client = Client.from_environment()

result = client.metric_sources.revoke_token('03eb8c34-ff18-4b02-987d-6231f5dcdb38')
```

**Response (200 OK)**

```json
{
  "data": {
    "uuid": "75666699-b77d-4631-b576-041e8102a55b",
    "name": "example",
    "slug": "example",
    "description": "example",
    "source_type": "example",
    "health_status": "example",
    "last_received_at": 1794214800000,
    "active": true,
    "has_ingest_token": true,
    "ingest_token_last_four": "example",
    "ingest_token_created_at": 1794214800000,
    "ingest_token_revoked_at": 1794214800000,
    "custom_metrics_count": 1,
    "max_requests_per_minute": 1,
    "created_at": 1794214800000,
    "tags": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      }
    ],
    "linked_servers": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      }
    ],
    "linked_servers_count": 1,
    "linked_server_all_tags": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "group": "example"
      }
    ],
    "linked_server_any_tags": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "group": "example"
      }
    ],
    "shown_on_servers_count": 1,
    "shown_on_servers": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      }
    ],
    "shown_metrics_count": 1
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the custom_metrics.delete scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid; `errors` names the parameters.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## Rotate a metric source's token

POST/v1/metric-sources/{metric\_source\_uuid}/rotate-token

Mints a new ingest token for the source, replacing any earlier one. The token is returned once, in this answer; a replay under the same `Idempotency-Key` answers it as null, so a caller that lost it rotates again under a new key.

Needs the scope `custom_metrics.edit`.

### Headers

- `Idempotency-Key` (string): Any text of 1 to 255 visible ASCII characters. A repeat of the same request within 24 hours returns the first answer without running again (the response carries `Idempotent-Replayed: true`); the same key on a different request is refused 422 `invalid_request`.

### Path parameters

- `metric_source_uuid` (string (uuid), required): The uuid of the metric source in the path.

### Returns

`200 OK`:

The new ingest token, shown once.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**POST /v1/metric-sources/{metric_source_uuid}/rotate-token**

curl:

```bash
curl -X POST https://rest.watchtower15.com/v1/metric-sources/03eb8c34-ff18-4b02-987d-6231f5dcdb38/rotate-token \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

$result = $wt15->metricSources->rotateToken('03eb8c34-ff18-4b02-987d-6231f5dcdb38');
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

const result = await wt15.metricSources.rotateToken('03eb8c34-ff18-4b02-987d-6231f5dcdb38');
```

Python:

```python
client = Client.from_environment()

result = client.metric_sources.rotate_token('03eb8c34-ff18-4b02-987d-6231f5dcdb38')
```

**Response (200 OK)**

```json
{
  "data": {
    "uuid": "75666699-b77d-4631-b576-041e8102a55b",
    "ingest_token": "example",
    "ingest_token_last_four": "example"
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the custom_metrics.edit scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid; `errors` names the parameters.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## Get the series of a metric source's metrics

GET/v1/metric-sources/{metric\_source\_uuid}/series

Returns the series of every custom metric of the source, ordered by name, then key, 25 metrics a page. Each item is the metric’s series as `GET /v1/custom-metrics/{custom_metric_uuid}/series` answers it; the window and the step are given once, in `meta`. The window, `step`, `tz` and `aggregation` work as they do there (`tz` puts the `1d` and `1w` points on the zone’s local midnights and Mondays, and `meta` gives the `tz` sent), but `aggregation` takes only `avg`, `min`, `max` or `last`, which apply to the source’s `level` metrics: a `count` metric always reads its sum, and its item says `sum`. A step that cuts the window into more than 720 points is refused for the whole call. A metric whose window holds more samples than the store reads in one query ends the page with 422 asking for a shorter window. A metric awaiting approval is listed with `available: false` and an empty series. Pages by `page` and `per_page` (`limit` is the same as `per_page`); every page carries `current_page`, `per_page`, `last_page` and `total`.

Needs the scope `custom_metrics.view`.

### Path parameters

- `metric_source_uuid` (string (uuid), required): The uuid of the metric source in the path.

### Query parameters

- `period` (string or null): A relative window ending now: 1 to 9999 minutes, hours, days or weeks (`3h`, `2w`). Not with `from` and `to`. The operation names its longest window and its default.
- `from` (string or null): The start of a pinned window, epoch milliseconds or RFC 3339 with an offset. Needs `to`. A start before the oldest data kept is served from it.
- `to` (string or null): The end of a pinned window, epoch milliseconds or RFC 3339 with an offset, after `from`. A window that ends before the oldest data kept, or in the future, is refused.
- `aggregation` (string or null): How each step of a `level` metric summarises its samples: `avg`, `min`, `max` or `last`. A `count` metric always reads its sum. Omitted, a level reads its value at each step. Values:`avg``min``max``last`(an open set: new values may be added)
- `step` (string or null): The width of one step: `30s`, `1m`, `5m`, `30m`, `2h`, `6h`, `1d` or `1w`, refused when it cuts the window into more than 720 points. Omitted, the step follows the window’s length. Values:`30s``1m``5m``30m``2h``6h``1d``1w`(an open set: new values may be added)
- `tz` (string or null): An IANA time zone name such as `Europe/London`. With a `1d` or `1w` step (sent, or chosen by the window’s length) each point sits at a local midnight of the zone, and a `1w` point on a Monday’s; with any other step it changes nothing. Omitted, the steps are aligned to UTC as before.
- `limit` (integer or null): The same as `per_page`, kept for existing clients.
- `per_page` (integer or null): The number of metrics in a page, from 1 to 25; 25 when omitted.
- `page` (integer or null): The page to read, from 1; 1 when omitted. A page past the last answers no rows.

### Returns

`200 OK`:

One page of the source’s metrics, each with its series.

Each item of the page:

- `available` (boolean): Whether the metric has data to chart: false while it awaits approval.
- `reason` (string or null): `awaiting_approval` while `available` is false; null otherwise.
- `aggregation` (string or null): `sum` for a `count` metric; for a `level` metric the `aggregation` sent, or null when none was sent.
- `metric` (object): The metric the series belongs to.
  - `uuid` (string): The metric’s uuid.
  - `name` (string): The metric’s name.
  - `metric_key` (string): The key a publisher sends the metric under.
  - `metric_type` (string): `count` or `level`.
  - `unit` (string or null): The unit the metric’s values are measured in; null for none.
- `series` (array of objects): One series for an approved metric, none while it awaits approval.
  - `name` (string): The metric’s key.
  - `unit` (string or null): The metric’s unit.
  - `labels` (object): The label values of the series; every one is null for a custom metric.
    - `mount` (string or null): Always null on a custom series.
    - `device` (string or null): Always null on a custom series.
    - `interface` (string or null): Always null on a custom series.
    - `state` (string or null): Always null on a custom series.
    - `cpu` (string or null): Always null on a custom series.
  - `point_meaning` (string): `count_per_step` (a `count` metric, summed per step) or `value_per_step` (a `level` metric).
  - `points` (array of arrays): `[t, value]` pairs, `t` in epoch milliseconds.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**GET /v1/metric-sources/{metric_source_uuid}/series**

curl:

```bash
curl https://rest.watchtower15.com/v1/metric-sources/03eb8c34-ff18-4b02-987d-6231f5dcdb38/series \
  -H "Authorization: Bearer $WT15_API_KEY"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

foreach ($wt15->metricSources->series('03eb8c34-ff18-4b02-987d-6231f5dcdb38')->autoPaging() as $item) { echo json_encode($item), "\n"; }
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

for await (const item of wt15.metricSources.series('03eb8c34-ff18-4b02-987d-6231f5dcdb38')) {
  console.log(item);
}
```

Python:

```python
client = Client.from_environment()

for item in client.metric_sources.series('03eb8c34-ff18-4b02-987d-6231f5dcdb38'):
    print(item)
```

**Response (200 OK)**

```json
{
  "data": [
    {
      "available": true,
      "reason": "example",
      "aggregation": "example",
      "metric": {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "metric_key": "example",
        "metric_type": "example",
        "unit": "example"
      },
      "series": [
        {
          "name": "example",
          "unit": "example",
          "labels": {
            "mount": "example",
            "device": "example",
            "interface": "example",
            "state": "example",
            "cpu": "example"
          },
          "point_meaning": "example",
          "points": [
            []
          ]
        }
      ]
    }
  ],
  "current_page": 1,
  "per_page": 1,
  "last_page": 1,
  "total": 1,
  "meta": {
    "window": {
      "from": 1794214800000,
      "to": 1794214800000
    },
    "step_seconds": 1,
    "tz": "example"
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the custom_metrics.view scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid (`invalid_request`; `errors` names the parameters).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (503 Service Unavailable)**

A data store did not answer within the request's 10 seconds; try again shortly (`store_unavailable`).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/store_unavailable/",
  "title": "Store unavailable",
  "status": 503,
  "code": "store_unavailable",
  "detail": "A data store did not answer; try again shortly",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## Get the summaries of a metric source's metrics

GET/v1/metric-sources/{metric\_source\_uuid}/summary

Returns, for every custom metric of the source, the statistics `GET /v1/custom-metrics/{custom_metric_uuid}/summary` answers, over one window that defaults to the last day and reaches back as far as the metrics are kept (1,095 days; an earlier start is served from it), given once in `meta` with `rolled_up`, which says whether a window longer than 31 days was read from the daily summaries (`p50` and `p95` are then approximations, as in the single summary). Metrics are ordered by name, then key, 25 a page. A metric whose history is not summarised yet is listed with `available: false` and `reason: rollup_pending`. A window of 31 days or less that the store refuses because it holds more samples than one query reads answers 422 asking for a shorter window; data denser than the default 100,000 points a day can also end at the read budget with 503 `store_unavailable`. A shorter window, or a smaller `per_page`, then answers. A metric awaiting approval is listed with `available: false` and every statistic null. Pages by `page` and `per_page` (`limit` is the same as `per_page`); every page carries `current_page`, `per_page`, `last_page` and `total`.

Needs the scope `custom_metrics.view`.

### Path parameters

- `metric_source_uuid` (string (uuid), required): The uuid of the metric source in the path.

### Query parameters

- `period` (string or null): A relative window ending now: 1 to 9999 minutes, hours, days or weeks (`3h`, `2w`). Not with `from` and `to`. The operation names its longest window and its default.
- `from` (string or null): The start of a pinned window, epoch milliseconds or RFC 3339 with an offset. Needs `to`. A start before the oldest data kept is served from it.
- `to` (string or null): The end of a pinned window, epoch milliseconds or RFC 3339 with an offset, after `from`. A window that ends before the oldest data kept, or in the future, is refused.
- `limit` (integer or null): The same as `per_page`, kept for existing clients.
- `per_page` (integer or null): The number of metrics in a page, from 1 to 25; 25 when omitted.
- `page` (integer or null): The page to read, from 1; 1 when omitted. A page past the last answers no rows.

### Returns

`200 OK`:

One page of the source’s metrics, each with its statistics.

Each item of the page:

- `available` (boolean): Whether the metric has samples to summarise: false while it awaits approval.
- `reason` (string or null): `awaiting_approval` while the metric awaits approval, `rollup_pending` while a window longer than 31 days cannot be answered yet (the metric’s history is not summarised yet, or a day of the window is not recomputed yet); null while `available` is true.
- `metric` (object): The metric the statistics belong to.
  - `uuid` (string): The metric’s uuid.
  - `name` (string): The metric’s name.
  - `metric_key` (string): The key a publisher sends the metric under.
  - `metric_type` (string): `count` or `level`.
  - `unit` (string or null): The unit the metric’s values are measured in; null for none.
- `sample_count` (integer or null): The number of samples in the window; null when it holds none.
- `sum` (number or null): The sum of the samples’ values; null when the window holds none.
- `min` (number or null): The smallest value; null when the window holds no sample.
- `max` (number or null): The largest value; null when the window holds no sample.
- `avg` (number or null): The average value; null when the window holds no sample.
- `p50` (number or null): The median value; null when the window holds no sample. Over 31 days (`rolled_up`) an approximation from a histogram of the values, within about 14% of the exact value, and null when the window holds a negative value.
- `p95` (number or null): The 95th percentile of the values; null when the window holds no sample. Over 31 days (`rolled_up`) an approximation from a histogram of the values, within about 14% of the exact value, and null when the window holds a negative value.
- `first_at` (integer or null): Epoch milliseconds. When the window’s first sample was taken; null when it holds none. An instant: epoch milliseconds, UTC.
- `last_at` (integer or null): Epoch milliseconds. When the window’s last sample was taken; null when it holds none. An instant: epoch milliseconds, UTC.
- `last` (number or null): The window’s last value; null when it holds no sample.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**GET /v1/metric-sources/{metric_source_uuid}/summary**

curl:

```bash
curl https://rest.watchtower15.com/v1/metric-sources/03eb8c34-ff18-4b02-987d-6231f5dcdb38/summary \
  -H "Authorization: Bearer $WT15_API_KEY"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

foreach ($wt15->metricSources->summary('03eb8c34-ff18-4b02-987d-6231f5dcdb38')->autoPaging() as $item) { echo json_encode($item), "\n"; }
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

for await (const item of wt15.metricSources.summary('03eb8c34-ff18-4b02-987d-6231f5dcdb38')) {
  console.log(item);
}
```

Python:

```python
client = Client.from_environment()

for item in client.metric_sources.summary('03eb8c34-ff18-4b02-987d-6231f5dcdb38'):
    print(item)
```

**Response (200 OK)**

```json
{
  "data": [
    {
      "available": true,
      "reason": "example",
      "metric": {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example",
        "metric_key": "example",
        "metric_type": "example",
        "unit": "example"
      },
      "sample_count": 1,
      "sum": 0,
      "min": 0,
      "max": 0,
      "avg": 0,
      "p50": 0,
      "p95": 0,
      "first_at": 1794214800000,
      "last_at": 1794214800000,
      "last": 0
    }
  ],
  "current_page": 1,
  "per_page": 1,
  "last_page": 1,
  "total": 1,
  "meta": {
    "window": {
      "from": 1794214800000,
      "to": 1794214800000
    },
    "rolled_up": true
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the custom_metrics.view scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid (`invalid_request`; `errors` names the parameters).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (503 Service Unavailable)**

A data store did not answer within the request's 10 seconds; try again shortly (`store_unavailable`).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/store_unavailable/",
  "title": "Store unavailable",
  "status": 503,
  "code": "store_unavailable",
  "detail": "A data store did not answer; try again shortly",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

Source: https://developer.watchtower15.com/api/reference/metric-sources/
