# Logs

Search, count and facet the organisation’s collected log lines over a time window.

Its operations need the scope `logs.view`.

**Endpoints**

- `GET/v1/logs/{line_uuid}`
- `GET/v1/logs/context`
- `GET/v1/logs/facets`
- `GET/v1/logs/groups`
- `GET/v1/logs/histogram`
- `GET/v1/logs`

## Read one log line

GET/v1/logs/{line\_uuid}

Returns one log line named by its `uuid` and the `at` time of the console link that shows it (`/logs/<uuid>?at=<time>`), with its full text, its exact `time` to the nanosecond, where that time comes from (`time_source`) and, for a Log Source line, the text the sender submitted (`raw_line`). `at` is the link’s `at` as it is, or the line’s `logged_at` in epoch milliseconds. A line that is gone, or that is not one of the organisation’s server or log source lines, is a 422.

Needs the scope `logs.view`.

### Path parameters

- `line_uuid` (string, required): The line’s `uuid`, as a search answers it and the console’s link carries it.

### Query parameters

- `at` (string, required): The line’s `time` (RFC 3339 with an offset, up to nine fraction digits: the console link’s `at` is passed as it is) or its `logged_at` (epoch milliseconds). It bounds the lookup of the line, so it is required.

### Returns

`200 OK`:

The log line.

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/logs/{line_uuid}**

curl:

```bash
curl -G https://rest.watchtower15.com/v1/logs/ee81acbe-c8d5-434d-8194-aeacb8784a0b \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -d at=example
```

PHP:

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

$result = $wt15->logs->view('ee81acbe-c8d5-434d-8194-aeacb8784a0b', ['at' => 'example']);
```

Node.js:

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

const result = await wt15.logs.view('ee81acbe-c8d5-434d-8194-aeacb8784a0b', { at: 'example' });
```

Python:

```python
client = Client.from_environment()

result = client.logs.view('ee81acbe-c8d5-434d-8194-aeacb8784a0b', at='example')
```

**Response (200 OK)**

```json
{
  "data": {
    "uuid": "75666699-b77d-4631-b576-041e8102a55b",
    "logged_at": 1794214800000,
    "time": "example",
    "console_url": "example",
    "time_source": "example",
    "received_at": 1794214800000,
    "level": "example",
    "stream": "example",
    "message": "example",
    "source": {
      "type": "example",
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "name": "example"
    },
    "unit": "example",
    "identifier": "example",
    "http": {
      "status": 1,
      "method": "example",
      "path": "example",
      "upstream_status": "example",
      "duration_ms": 1
    },
    "raw_line": "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 logs.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"
}
```

## Read the lines around a log line

GET/v1/logs/context

Returns the lines logged just before and just after one line of the same source and stream, newest first, with the line itself marked `is_anchor`. Name the line by its `uuid` and `logged_at` from a search. `before` and `after` count lines, 20 each by default and 100 at most; `has_older_more` and `has_newer_more` say whether more lines exist beyond them. A line that is gone, or that is not one of the organisation’s server or log source lines, is a 422.

Needs the scope `logs.view`.

### Query parameters

- `uuid` (string, required): The line’s `uuid`, as the search answers it.
- `at` (string, required): When the line was logged (its `logged_at`, epoch milliseconds, or RFC 3339 with an offset): it bounds the lookup of the line.
- `before` (integer or null): The number of older lines to return, from 0 to 100; 20 when omitted.
- `after` (integer or null): The number of newer lines to return, from 0 to 100; 20 when omitted.

### Returns

`200 OK`:

The lines around the line asked, newest first.

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/logs/context**

curl:

```bash
curl -G https://rest.watchtower15.com/v1/logs/context \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -d uuid=75666699-b77d-4631-b576-041e8102a55b \
  -d at=example
```

PHP:

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

$result = $wt15->logs->context(['uuid' => '75666699-b77d-4631-b576-041e8102a55b', 'at' => 'example']);
```

Node.js:

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

const result = await wt15.logs.context({ uuid: '75666699-b77d-4631-b576-041e8102a55b', at: 'example' });
```

Python:

```python
client = Client.from_environment()

result = client.logs.context(uuid='75666699-b77d-4631-b576-041e8102a55b', at='example')
```

**Response (200 OK)**

```json
{
  "data": {
    "items": [
      {
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "logged_at": 1794214800000,
        "time": "example",
        "console_url": "example",
        "time_source": "example",
        "received_at": 1794214800000,
        "level": "example",
        "stream": "example",
        "message": "example",
        "source": {
          "type": "example",
          "uuid": "75666699-b77d-4631-b576-041e8102a55b",
          "name": "example"
        },
        "unit": "example",
        "identifier": "example",
        "http": {
          "status": 1,
          "method": "example",
          "path": "example",
          "upstream_status": "example",
          "duration_ms": 1
        },
        "is_anchor": true
      }
    ],
    "has_newer_more": true,
    "has_older_more": 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 logs.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"
}
```

## Count logs by level and stream

GET/v1/logs/facets

Counts the lines the search filters match by level and by stream, most first. The window defaults to the last hour and reaches back to retention (30 days); a window that ends in the future ends now, and `window` says the window read. Lines with no level are not counted in the levels but in `unlevelled_count` (select them with `levels[]=unknown`), and the stream list ignores the stream filter so every candidate stream stays listed.

Needs the scope `logs.view`.

### Query parameters

- `source_uuids` (array of strings or null): Only lines from these servers or log sources, by uuid (a server’s uuid gives that server’s lines); a deleted one’s lines stay searchable for the retention. A list: repeat the parameter (`source_uuids=<uuid>&source_uuids=<uuid>`) or send one value (`source_uuids=<uuid>`); `source_uuids[]=<uuid>` is accepted too.
- `levels` (array of strings or null): Only lines at one of these levels: `debug`, `info`, `notice`, `warning`, `error`, `critical`, `alert` or `emergency`; `unknown` selects the lines with no level (their `level` is null). A list: repeat the parameter (`levels=debug&levels=info`) or send one value (`levels=debug`); `levels[]=debug` is accepted too. Values:`debug``info``notice``warning``error``critical``alert``emergency``unknown`(an open set: new values may be added)
- `streams` (array of strings or null): Only lines in one of these streams. A list: repeat the parameter (`streams=<value>&streams=<value>`) or send one value (`streams=<value>`); `streams[]=<value>` is accepted too.
- `search` (string or null): Only lines whose text contains this text.
- `tag_uuids` (array of strings or null): Only lines from servers and log sources carrying any of these tags, by uuid. A list: repeat the parameter (`tag_uuids=<uuid>&tag_uuids=<uuid>`) or send one value (`tag_uuids=<uuid>`); `tag_uuids[]=<uuid>` is accepted too.
- `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 is refused; one that ends in the future ends now, and the answer’s window says so.
- `exclude` (array of strings or null): Only lines that contain none of these texts: at most 5, each at most 200 characters. `search_case` applies to them; `search_mode` does not, they are always literal text. A list: repeat the parameter (`exclude=<value>&exclude=<value>`) or send one value (`exclude=<value>`); `exclude[]=<value>` is accepted too.
- `search_mode` (string or null): How `search` is read: `substring` (the default) or `regex`, an RE2 pattern of at most 500 characters with no lookahead, lookbehind, backreference, possessive quantifier or atomic group. Values:`substring``regex`(an open set: new values may be added)
- `search_case` (string or null): Whether `search` and `exclude` ignore case: `sensitive` (the default) or `insensitive`. It sets the case of every include and exclude list too. Values:`sensitive``insensitive`(an open set: new values may be added)
- `units` (array of strings or null): Only lines from these systemd units, exactly (`cloudflared.service`): at most 20. Null on lines that did not come from a journal, and on lines from an agent too old to report the unit. A list: repeat the parameter (`units=<value>&units=<value>`) or send one value (`units=<value>`); `units[]=<value>` is accepted too.
- `identifiers` (array of strings or null): Only lines with these journal identifiers (`SYSLOG_IDENTIFIER`, such as `sshd`), exactly: at most 20. A list: repeat the parameter (`identifiers=<value>&identifiers=<value>`) or send one value (`identifiers=<value>`); `identifiers[]=<value>` is accepted too.
- `http_statuses` (array of strings or null): Only lines whose parsed HTTP status is one of these: a code (`502`) or a class (`5xx`), at most 10. Only access log lines the backend parsed (a file entry with a `format`) have a status. A list: repeat the parameter (`http_statuses=<value>&http_statuses=<value>`) or send one value (`http_statuses=<value>`); `http_statuses[]=<value>` is accepted too.
- `include` (array of strings or null): Only lines that contain each of these texts (or any of them, with `match=any`): literal text of 1 to 500 characters. A search holds at most 10 terms: `search`, `exclude` and every include and exclude list count together. A list: repeat the parameter (`include=<value>&include=<value>`) or send one value (`include=<value>`); `include[]=<value>` is accepted too.
- `include_words` (array of strings or null): Only lines that contain each of these whole words: a word is bounded where its first and last characters are letters, digits or underscores (ASCII only, so `café` is bounded at `caf`). A list: repeat the parameter (`include_words=<value>&include_words=<value>`) or send one value (`include_words=<value>`); `include_words[]=<value>` is accepted too.
- `include_regex` (array of strings or null): Only lines that match each of these RE2 regular expressions: no lookahead, lookbehind, backreference, possessive quantifier or atomic group. At most 5 regex terms, with `exclude_regex` and a `search` with `search_mode=regex`. Start one with `(?i)` to ignore case in that term alone. A list: repeat the parameter (`include_regex=<value>&include_regex=<value>`) or send one value (`include_regex=<value>`); `include_regex[]=<value>` is accepted too.
- `exclude_words` (array of strings or null): Only lines that contain none of these whole words. A list: repeat the parameter (`exclude_words=<value>&exclude_words=<value>`) or send one value (`exclude_words=<value>`); `exclude_words[]=<value>` is accepted too.
- `exclude_regex` (array of strings or null): Only lines that match none of these RE2 regular expressions, as `include_regex` takes them. A list: repeat the parameter (`exclude_regex=<value>&exclude_regex=<value>`) or send one value (`exclude_regex=<value>`); `exclude_regex[]=<value>` is accepted too.
- `match` (string or null): How the included terms combine: `all` (the default), a line matches every one, or `any`, at least one; the excluded terms always apply. Needs an included term (`search`, `include`, `include_words` or `include_regex`). `search_case` sets the case of every term. Values:`all``any`(an open set: new values may be added)

### Returns

`200 OK`:

The level and stream counts of the matching lines.

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/logs/facets**

curl:

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

PHP:

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

$result = $wt15->logs->facets();
```

Node.js:

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

const result = await wt15.logs.facets();
```

Python:

```python
client = Client.from_environment()

result = client.logs.facets()
```

**Response (200 OK)**

```json
{
  "data": {
    "window": {
      "from": 1794214800000,
      "to": 1794214800000
    },
    "levels": [
      {
        "level": "example",
        "count": 1
      }
    ],
    "unlevelled_count": 1,
    "streams": [
      {
        "stream": "example",
        "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 logs.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"
}
```

## Count logs by a field

GET/v1/logs/groups

Counts the lines the search filters match by one field (stream, level, source, unit, identifier, HTTP status, HTTP path or message pattern), most first, `by=pattern` counts the messages with their numbers, UUIDs, addresses and times replaced by placeholders (`<N>`, `<UUID>`, `<IP4>`, `<TIME>`), so repeated errors count as one pattern instead of being downloaded; at most 100 groups. The window defaults to the last hour and reaches back to retention (30 days); a window that ends in the future ends now, and `window` says the window read. A line without the field is counted under a null value.

Needs the scope `logs.view`.

### Query parameters

- `by` (string, required): What to count the lines by: `stream`, `level`, `source`, `unit`, `identifier`, `http_status`, `http_path` or `pattern` (the message with its numbers, hexadecimal values, UUIDs, addresses and times replaced by placeholders such as `<N>`, `<UUID>`, `<IP4>` and `<TIME>`, most frequent first; each value cut at 1,000 characters). Values:`stream``level``source``unit``identifier``http_status``http_path``pattern`(an open set: new values may be added)
- `source_uuids` (array of strings or null): Only lines from these servers or log sources, by uuid (a server’s uuid gives that server’s lines); a deleted one’s lines stay searchable for the retention. A list: repeat the parameter (`source_uuids=<uuid>&source_uuids=<uuid>`) or send one value (`source_uuids=<uuid>`); `source_uuids[]=<uuid>` is accepted too.
- `levels` (array of strings or null): Only lines at one of these levels: `debug`, `info`, `notice`, `warning`, `error`, `critical`, `alert` or `emergency`; `unknown` selects the lines with no level (their `level` is null). A list: repeat the parameter (`levels=debug&levels=info`) or send one value (`levels=debug`); `levels[]=debug` is accepted too. Values:`debug``info``notice``warning``error``critical``alert``emergency``unknown`(an open set: new values may be added)
- `streams` (array of strings or null): Only lines in one of these streams. A list: repeat the parameter (`streams=<value>&streams=<value>`) or send one value (`streams=<value>`); `streams[]=<value>` is accepted too.
- `search` (string or null): Only lines whose text contains this text.
- `tag_uuids` (array of strings or null): Only lines from servers and log sources carrying any of these tags, by uuid. A list: repeat the parameter (`tag_uuids=<uuid>&tag_uuids=<uuid>`) or send one value (`tag_uuids=<uuid>`); `tag_uuids[]=<uuid>` is accepted too.
- `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 number of groups, from 1 to 100; 50 when omitted.
- `exclude` (array of strings or null): Only lines that contain none of these texts: at most 5, each at most 200 characters. `search_case` applies to them; `search_mode` does not, they are always literal text. A list: repeat the parameter (`exclude=<value>&exclude=<value>`) or send one value (`exclude=<value>`); `exclude[]=<value>` is accepted too.
- `search_mode` (string or null): How `search` is read: `substring` (the default) or `regex`, an RE2 pattern of at most 500 characters with no lookahead, lookbehind, backreference, possessive quantifier or atomic group. Values:`substring``regex`(an open set: new values may be added)
- `search_case` (string or null): Whether `search` and `exclude` ignore case: `sensitive` (the default) or `insensitive`. It sets the case of every include and exclude list too. Values:`sensitive``insensitive`(an open set: new values may be added)
- `units` (array of strings or null): Only lines from these systemd units, exactly (`cloudflared.service`): at most 20. Null on lines that did not come from a journal, and on lines from an agent too old to report the unit. A list: repeat the parameter (`units=<value>&units=<value>`) or send one value (`units=<value>`); `units[]=<value>` is accepted too.
- `identifiers` (array of strings or null): Only lines with these journal identifiers (`SYSLOG_IDENTIFIER`, such as `sshd`), exactly: at most 20. A list: repeat the parameter (`identifiers=<value>&identifiers=<value>`) or send one value (`identifiers=<value>`); `identifiers[]=<value>` is accepted too.
- `http_statuses` (array of strings or null): Only lines whose parsed HTTP status is one of these: a code (`502`) or a class (`5xx`), at most 10. Only access log lines the backend parsed (a file entry with a `format`) have a status. A list: repeat the parameter (`http_statuses=<value>&http_statuses=<value>`) or send one value (`http_statuses=<value>`); `http_statuses[]=<value>` is accepted too.
- `include` (array of strings or null): Only lines that contain each of these texts (or any of them, with `match=any`): literal text of 1 to 500 characters. A search holds at most 10 terms: `search`, `exclude` and every include and exclude list count together. A list: repeat the parameter (`include=<value>&include=<value>`) or send one value (`include=<value>`); `include[]=<value>` is accepted too.
- `include_words` (array of strings or null): Only lines that contain each of these whole words: a word is bounded where its first and last characters are letters, digits or underscores (ASCII only, so `café` is bounded at `caf`). A list: repeat the parameter (`include_words=<value>&include_words=<value>`) or send one value (`include_words=<value>`); `include_words[]=<value>` is accepted too.
- `include_regex` (array of strings or null): Only lines that match each of these RE2 regular expressions: no lookahead, lookbehind, backreference, possessive quantifier or atomic group. At most 5 regex terms, with `exclude_regex` and a `search` with `search_mode=regex`. Start one with `(?i)` to ignore case in that term alone. A list: repeat the parameter (`include_regex=<value>&include_regex=<value>`) or send one value (`include_regex=<value>`); `include_regex[]=<value>` is accepted too.
- `exclude_words` (array of strings or null): Only lines that contain none of these whole words. A list: repeat the parameter (`exclude_words=<value>&exclude_words=<value>`) or send one value (`exclude_words=<value>`); `exclude_words[]=<value>` is accepted too.
- `exclude_regex` (array of strings or null): Only lines that match none of these RE2 regular expressions, as `include_regex` takes them. A list: repeat the parameter (`exclude_regex=<value>&exclude_regex=<value>`) or send one value (`exclude_regex=<value>`); `exclude_regex[]=<value>` is accepted too.
- `match` (string or null): How the included terms combine: `all` (the default), a line matches every one, or `any`, at least one; the excluded terms always apply. Needs an included term (`search`, `include`, `include_words` or `include_regex`). `search_case` sets the case of every term. Values:`all``any`(an open set: new values may be added)

### Returns

`200 OK`:

The line counts by the field asked, and the window read.

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/logs/groups**

curl:

```bash
curl -G https://rest.watchtower15.com/v1/logs/groups \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -d by=stream
```

PHP:

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

$result = $wt15->logs->groups(['by' => 'stream']);
```

Node.js:

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

const result = await wt15.logs.groups({ by: 'stream' });
```

Python:

```python
client = Client.from_environment()

result = client.logs.groups(by='stream')
```

**Response (200 OK)**

```json
{
  "data": {
    "window": {
      "from": 1794214800000,
      "to": 1794214800000
    },
    "groups": [
      {
        "value": "example",
        "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 logs.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"
}
```

## Count logs over time

GET/v1/logs/histogram

Counts the lines the search filters match per time bucket, split by level. The window defaults to the last day and reaches back to retention (30 days); a window that ends in the future ends now, and `window` says the window read. With no `step` the window is split into 48 buckets; a `step` that gives more than 1,440 buckets is refused. Only buckets that hold a line are returned.

Needs the scope `logs.view`.

### Query parameters

- `source_uuids` (array of strings or null): Only lines from these servers or log sources, by uuid (a server’s uuid gives that server’s lines); a deleted one’s lines stay searchable for the retention. A list: repeat the parameter (`source_uuids=<uuid>&source_uuids=<uuid>`) or send one value (`source_uuids=<uuid>`); `source_uuids[]=<uuid>` is accepted too.
- `levels` (array of strings or null): Only lines at one of these levels: `debug`, `info`, `notice`, `warning`, `error`, `critical`, `alert` or `emergency`; `unknown` selects the lines with no level (their `level` is null). A list: repeat the parameter (`levels=debug&levels=info`) or send one value (`levels=debug`); `levels[]=debug` is accepted too. Values:`debug``info``notice``warning``error``critical``alert``emergency``unknown`(an open set: new values may be added)
- `streams` (array of strings or null): Only lines in one of these streams. A list: repeat the parameter (`streams=<value>&streams=<value>`) or send one value (`streams=<value>`); `streams[]=<value>` is accepted too.
- `search` (string or null): Only lines whose text contains this text.
- `tag_uuids` (array of strings or null): Only lines from servers and log sources carrying any of these tags, by uuid. A list: repeat the parameter (`tag_uuids=<uuid>&tag_uuids=<uuid>`) or send one value (`tag_uuids=<uuid>`); `tag_uuids[]=<uuid>` is accepted too.
- `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 is refused; one that ends in the future ends now, and the answer’s window says so.
- `step` (string or null): The width of a bucket as a whole number and a unit, `s`, `m`, `h` or `d`, such as `5m`; at most 1,440 buckets for the window, and the window divided by 48 when omitted.
- `exclude` (array of strings or null): Only lines that contain none of these texts: at most 5, each at most 200 characters. `search_case` applies to them; `search_mode` does not, they are always literal text. A list: repeat the parameter (`exclude=<value>&exclude=<value>`) or send one value (`exclude=<value>`); `exclude[]=<value>` is accepted too.
- `search_mode` (string or null): How `search` is read: `substring` (the default) or `regex`, an RE2 pattern of at most 500 characters with no lookahead, lookbehind, backreference, possessive quantifier or atomic group. Values:`substring``regex`(an open set: new values may be added)
- `search_case` (string or null): Whether `search` and `exclude` ignore case: `sensitive` (the default) or `insensitive`. It sets the case of every include and exclude list too. Values:`sensitive``insensitive`(an open set: new values may be added)
- `units` (array of strings or null): Only lines from these systemd units, exactly (`cloudflared.service`): at most 20. Null on lines that did not come from a journal, and on lines from an agent too old to report the unit. A list: repeat the parameter (`units=<value>&units=<value>`) or send one value (`units=<value>`); `units[]=<value>` is accepted too.
- `identifiers` (array of strings or null): Only lines with these journal identifiers (`SYSLOG_IDENTIFIER`, such as `sshd`), exactly: at most 20. A list: repeat the parameter (`identifiers=<value>&identifiers=<value>`) or send one value (`identifiers=<value>`); `identifiers[]=<value>` is accepted too.
- `http_statuses` (array of strings or null): Only lines whose parsed HTTP status is one of these: a code (`502`) or a class (`5xx`), at most 10. Only access log lines the backend parsed (a file entry with a `format`) have a status. A list: repeat the parameter (`http_statuses=<value>&http_statuses=<value>`) or send one value (`http_statuses=<value>`); `http_statuses[]=<value>` is accepted too.
- `include` (array of strings or null): Only lines that contain each of these texts (or any of them, with `match=any`): literal text of 1 to 500 characters. A search holds at most 10 terms: `search`, `exclude` and every include and exclude list count together. A list: repeat the parameter (`include=<value>&include=<value>`) or send one value (`include=<value>`); `include[]=<value>` is accepted too.
- `include_words` (array of strings or null): Only lines that contain each of these whole words: a word is bounded where its first and last characters are letters, digits or underscores (ASCII only, so `café` is bounded at `caf`). A list: repeat the parameter (`include_words=<value>&include_words=<value>`) or send one value (`include_words=<value>`); `include_words[]=<value>` is accepted too.
- `include_regex` (array of strings or null): Only lines that match each of these RE2 regular expressions: no lookahead, lookbehind, backreference, possessive quantifier or atomic group. At most 5 regex terms, with `exclude_regex` and a `search` with `search_mode=regex`. Start one with `(?i)` to ignore case in that term alone. A list: repeat the parameter (`include_regex=<value>&include_regex=<value>`) or send one value (`include_regex=<value>`); `include_regex[]=<value>` is accepted too.
- `exclude_words` (array of strings or null): Only lines that contain none of these whole words. A list: repeat the parameter (`exclude_words=<value>&exclude_words=<value>`) or send one value (`exclude_words=<value>`); `exclude_words[]=<value>` is accepted too.
- `exclude_regex` (array of strings or null): Only lines that match none of these RE2 regular expressions, as `include_regex` takes them. A list: repeat the parameter (`exclude_regex=<value>&exclude_regex=<value>`) or send one value (`exclude_regex=<value>`); `exclude_regex[]=<value>` is accepted too.
- `match` (string or null): How the included terms combine: `all` (the default), a line matches every one, or `any`, at least one; the excluded terms always apply. Needs an included term (`search`, `include`, `include_words` or `include_regex`). `search_case` sets the case of every term. Values:`all``any`(an open set: new values may be added)

### Returns

`200 OK`:

The matching lines counted per time bucket.

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/logs/histogram**

curl:

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

PHP:

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

$result = $wt15->logs->histogram();
```

Node.js:

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

const result = await wt15.logs.histogram();
```

Python:

```python
client = Client.from_environment()

result = client.logs.histogram()
```

**Response (200 OK)**

```json
{
  "data": {
    "window": {
      "from": 1794214800000,
      "to": 1794214800000
    },
    "step_seconds": 1,
    "buckets": [
      {
        "start_at": 1794214800000,
        "total": 1,
        "by_level": {
          "debug": 1,
          "info": 1,
          "notice": 1,
          "warning": 1,
          "error": 1,
          "critical": 1,
          "alert": 1,
          "emergency": 1,
          "unknown": 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 logs.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"
}
```

## Search logs

GET/v1/logs

Searches the organisation’s server and log source lines, newest first, one page at a time. The window defaults to the last hour and reaches back to retention (30 days); a window that ends in the future ends now, and `meta.window` says the window read. Later pages keep the first page’s window. Filter by source, level, stream, tag and text. Its `total` is always null: the lines are not counted.

Needs the scope `logs.view`.

### Query parameters

- `source_uuids` (array of strings or null): Only lines from these servers or log sources, by uuid (a server’s uuid gives that server’s lines); a deleted one’s lines stay searchable for the retention. A list: repeat the parameter (`source_uuids=<uuid>&source_uuids=<uuid>`) or send one value (`source_uuids=<uuid>`); `source_uuids[]=<uuid>` is accepted too.
- `levels` (array of strings or null): Only lines at one of these levels: `debug`, `info`, `notice`, `warning`, `error`, `critical`, `alert` or `emergency`; `unknown` selects the lines with no level (their `level` is null). A list: repeat the parameter (`levels=debug&levels=info`) or send one value (`levels=debug`); `levels[]=debug` is accepted too. Values:`debug``info``notice``warning``error``critical``alert``emergency``unknown`(an open set: new values may be added)
- `streams` (array of strings or null): Only lines in one of these streams. A list: repeat the parameter (`streams=<value>&streams=<value>`) or send one value (`streams=<value>`); `streams[]=<value>` is accepted too.
- `search` (string or null): Only lines whose text contains this text.
- `tag_uuids` (array of strings or null): Only lines from servers and log sources carrying any of these tags, by uuid. A list: repeat the parameter (`tag_uuids=<uuid>&tag_uuids=<uuid>`) or send one value (`tag_uuids=<uuid>`); `tag_uuids[]=<uuid>` is accepted too.
- `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 is refused; one that ends in the future ends now, and the answer’s window says so.
- `limit` (integer or null): The same as `per_page`, kept for existing clients.
- `cursor` (string or null): The `next_cursor` of the previous page; omit it for the first page.
- `exclude` (array of strings or null): Only lines that contain none of these texts: at most 5, each at most 200 characters. `search_case` applies to them; `search_mode` does not, they are always literal text. A list: repeat the parameter (`exclude=<value>&exclude=<value>`) or send one value (`exclude=<value>`); `exclude[]=<value>` is accepted too.
- `search_mode` (string or null): How `search` is read: `substring` (the default) or `regex`, an RE2 pattern of at most 500 characters with no lookahead, lookbehind, backreference, possessive quantifier or atomic group. Values:`substring``regex`(an open set: new values may be added)
- `search_case` (string or null): Whether `search` and `exclude` ignore case: `sensitive` (the default) or `insensitive`. It sets the case of every include and exclude list too. Values:`sensitive``insensitive`(an open set: new values may be added)
- `units` (array of strings or null): Only lines from these systemd units, exactly (`cloudflared.service`): at most 20. Null on lines that did not come from a journal, and on lines from an agent too old to report the unit. A list: repeat the parameter (`units=<value>&units=<value>`) or send one value (`units=<value>`); `units[]=<value>` is accepted too.
- `identifiers` (array of strings or null): Only lines with these journal identifiers (`SYSLOG_IDENTIFIER`, such as `sshd`), exactly: at most 20. A list: repeat the parameter (`identifiers=<value>&identifiers=<value>`) or send one value (`identifiers=<value>`); `identifiers[]=<value>` is accepted too.
- `http_statuses` (array of strings or null): Only lines whose parsed HTTP status is one of these: a code (`502`) or a class (`5xx`), at most 10. Only access log lines the backend parsed (a file entry with a `format`) have a status. A list: repeat the parameter (`http_statuses=<value>&http_statuses=<value>`) or send one value (`http_statuses=<value>`); `http_statuses[]=<value>` is accepted too.
- `include` (array of strings or null): Only lines that contain each of these texts (or any of them, with `match=any`): literal text of 1 to 500 characters. A search holds at most 10 terms: `search`, `exclude` and every include and exclude list count together. A list: repeat the parameter (`include=<value>&include=<value>`) or send one value (`include=<value>`); `include[]=<value>` is accepted too.
- `include_words` (array of strings or null): Only lines that contain each of these whole words: a word is bounded where its first and last characters are letters, digits or underscores (ASCII only, so `café` is bounded at `caf`). A list: repeat the parameter (`include_words=<value>&include_words=<value>`) or send one value (`include_words=<value>`); `include_words[]=<value>` is accepted too.
- `include_regex` (array of strings or null): Only lines that match each of these RE2 regular expressions: no lookahead, lookbehind, backreference, possessive quantifier or atomic group. At most 5 regex terms, with `exclude_regex` and a `search` with `search_mode=regex`. Start one with `(?i)` to ignore case in that term alone. A list: repeat the parameter (`include_regex=<value>&include_regex=<value>`) or send one value (`include_regex=<value>`); `include_regex[]=<value>` is accepted too.
- `exclude_words` (array of strings or null): Only lines that contain none of these whole words. A list: repeat the parameter (`exclude_words=<value>&exclude_words=<value>`) or send one value (`exclude_words=<value>`); `exclude_words[]=<value>` is accepted too.
- `exclude_regex` (array of strings or null): Only lines that match none of these RE2 regular expressions, as `include_regex` takes them. A list: repeat the parameter (`exclude_regex=<value>&exclude_regex=<value>`) or send one value (`exclude_regex=<value>`); `exclude_regex[]=<value>` is accepted too.
- `match` (string or null): How the included terms combine: `all` (the default), a line matches every one, or `any`, at least one; the excluded terms always apply. Needs an included term (`search`, `include`, `include_words` or `include_regex`). `search_case` sets the case of every term. Values:`all``any`(an open set: new values may be added)
- `per_page` (integer or null): The number of lines in a page, from 1 to 2,000; 100 when omitted. A page of long lines can be shorter: it stops once the lines’ text passes 10 MB, and `next_cursor` continues after the last line returned.

### Returns

`200 OK`:

One page of the matching log lines.

Each item of the page:

- `uuid` (string or null): The line’s uuid, which `GET /v1/logs/context` takes to read the lines around it.
- `logged_at` (integer or null): Epoch milliseconds. When the line was logged. An instant: epoch milliseconds, UTC.
- `time` (string or null): The exact time the line is stored at: RFC 3339 UTC with nine fraction digits, so lines inside one millisecond are ordered. Take it with `uuid` to read the line (`GET /v1/logs/{line_uuid}`).
- `console_url` (string or null): The console’s page of this line (`/logs/<uuid>?at=<time>`); null for a line with no uuid.
- `time_source` (string): Where `logged_at` and `time` come from: `read` (the moment the agent read the line from its file, up to its 15-second collection interval after the event: not the event’s time), `parsed` or `late` (the time written in the line’s text), `journal` (the journal’s event time), `event_log` (the Windows event’s own time), `sender` (the time a Log Source’s sender gave) or `received` (the backend’s receipt time, because the sender gave none that could be used).
- `received_at` (integer or null): Epoch milliseconds. When the backend received the batch the line came in; null for a line stored without it. An instant: epoch milliseconds, UTC.
- `level` (string or null): One of `debug`, `info`, `notice`, `warning`, `error`, `critical`, `alert`, `emergency`; null for a line with no level.
- `stream` (string or null): The stream the line belongs to; null for a line with no stream.
- `message` (string): The line’s text.
- `source` (object): Where the line came from.
  - `type` (string): `server` or `log_source`.
  - `uuid` (string or null): The source’s uuid.
  - `name` (string or null): The source’s name; a deleted source reads as the console labels it.
- `unit` (string or null): The systemd unit that wrote the line (`cloudflared.service`); null for a line that did not come from a journal and for a line from an agent too old to report the unit.
- `identifier` (string or null): The journal identifier (`SYSLOG_IDENTIFIER`, such as `sshd`); null as `unit` is.
- `http` (object or null): The access line’s parsed fields; null for a line the backend did not parse: only a server file entry with a `format` is.
  - `status` (integer): The HTTP status code.
  - `method` (string or null): The request method; null when the request line could not be read.
  - `path` (string or null): The request path without its query string; null when the request line could not be read.
  - `upstream_status` (string or null): The upstream’s status as nginx wrote it (`502, 502` when it tried twice); null when there was none, and for every format but `wt15_relay`.
  - `duration_ms` (integer or null): How long the request took, in milliseconds; null for the `nginx_combined` format.

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/logs**

curl:

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

PHP:

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

foreach ($wt15->logs->search()->autoPaging() as $item) { echo $item->uuid, "\n"; }
```

Node.js:

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

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

Python:

```python
client = Client.from_environment()

for item in client.logs.search():
    print(item.uuid)
```

**Response (200 OK)**

```json
{
  "data": [
    {
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "logged_at": 1794214800000,
      "time": "example",
      "console_url": "example",
      "time_source": "example",
      "received_at": 1794214800000,
      "level": "example",
      "stream": "example",
      "message": "example",
      "source": {
        "type": "example",
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      },
      "unit": "example",
      "identifier": "example",
      "http": {
        "status": 1,
        "method": "example",
        "path": "example",
        "upstream_status": "example",
        "duration_ms": 1
      }
    }
  ],
  "next_cursor": "example",
  "total": 1,
  "meta": {
    "window": {
      "from": 1794214800000,
      "to": 1794214800000
    }
  }
}
```

**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 logs.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/logs/
