# Logs ingest

Send log lines with a log source’s token.

Its operations take the source's token as `Authorization: Bearer <token>`, never an API key.

**Endpoints**

- `POST/api/log-sources/ingest`

## Send log lines

POST/api/log-sources/ingest

Sends a batch of log lines with a log source’s token. The body is a JSON envelope `{"lines": […]}`, a JSON array, one line or newline-delimited JSON, any of them gzipped. Each line carries a `message` and optionally `logged_at`, `log_level`, `stream_name` and `raw_line`. An `Idempotency-Key` makes a retry of the same batch safe for 24 hours.

**Limits** (by default):

-   1,000 lines in one request.
-   A body of 5,242,880 bytes as sent and 20,971,520 bytes after decompression.
-   A message of at most 65,536 bytes.
-   A `logged_at` more than 300 seconds ahead is clamped to now.
-   600 requests a minute for each source.

### Headers

- `Idempotency-Key` (string): Any text of 1 to 255 visible ASCII characters. A repeat of the same batch with the same key within 24 hours is answered as the first was, with the first batch’s `batch_id` and `lines`, and stored once. A different batch under a key used in the last 24 hours is refused with `422`.

### Body parameters

- `lines` (array of objects, required): The lines of the batch.
  - `message` (string, required): The log line. A line without one is skipped.
  - `logged_at` (string): When the line was logged: RFC 3339, or a Unix epoch in seconds or milliseconds as a number or a string. A time without a timezone is read as UTC. A missing or unreadable time is the time the line was received.
  - `log_level` (string): The line’s level. Anything else is dropped rather than stored. Values:`debug``info``notice``warning``error``critical``alert``emergency`(an open set: new values may be added)
  - `stream_name` (string): The stream the line belongs to; defaults to the source’s slug. Keep it low-cardinality: a stable label, never an id or a timestamp.
  - `log_source` (string): An alias for `stream_name`, so an agent-shaped payload works unchanged.
  - `raw_line` (string): The original unparsed line, if there is one.

### Returns

`200 OK`:

What was stored and how many lines the batch held.

The response panel's status selector shows each failure this operation can answer.

**POST /api/log-sources/ingest**

curl:

```bash
curl -X POST https://api.watchtower15.com/api/log-sources/ingest \
  -H "Authorization: Bearer $WT15_LOGS_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "lines": [
      {
        "message": "example"
      }
    ]
  }'
```

PHP:

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

$result = $wt15->ingest->logs->push([['message' => 'example']]);
```

Node.js:

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

const result = await wt15.ingest.logs.push([{ message: 'example' }]);
```

Python:

```python
client = Client.from_environment()

result = client.ingest.logs.push([{'message': 'example'}])
```

**Response (200 OK)**

```json
{
  "status": "success",
  "status_code": 1,
  "data": {
    "accepted": true,
    "batch_id": "example",
    "lines": 1
  },
  "request_id": "example",
  "timestamp": 1794214800000,
  "message": "example"
}
```

**Response (400 Bad Request)**

The body is empty, or is not one of the accepted forms, or cannot be decompressed.

```json
{
  "status": "failure",
  "status_code": 400,
  "data": null,
  "request_id": "example",
  "timestamp": 1794214800000,
  "message": "example",
  "errors": {}
}
```

**Response (403 Forbidden)**

The token is missing, malformed, unknown, switched off or belongs to another kind of source. Every failure to authenticate is this one answer.

```json
{
  "status": "failure",
  "status_code": 403,
  "data": null,
  "request_id": "example",
  "timestamp": 1794214800000,
  "message": "example",
  "errors": {}
}
```

**Response (413 Content Too Large)**

The body is larger than the limit, or holds more lines than a request may.

```json
{
  "status": "failure",
  "status_code": 413,
  "data": null,
  "request_id": "example",
  "timestamp": 1794214800000,
  "message": "example",
  "errors": {}
}
```

**Response (422 Unprocessable Content)**

The `Idempotency-Key` was used in the last 24 hours for a different batch; `data.code` is `idempotency_key_reused` and `errors` names the header.

```json
{
  "status": "failure",
  "status_code": 422,
  "data": {
    "code": "example"
  },
  "request_id": "example",
  "timestamp": 1794214800000,
  "message": "example",
  "errors": {}
}
```

**Response (429 Too Many Requests)**

A rate limit is reached, or the organisation's log volume is stopped; `Retry-After` says how many seconds to wait, and for a stop `data` holds `code` `log_volume_limit_reached` and `resumes_at`.

```json
{
  "status": "failure",
  "status_code": 429,
  "data": {
    "code": "example",
    "resumes_at": 1794214800000
  },
  "request_id": "example",
  "timestamp": 1794214800000,
  "message": "example",
  "errors": {}
}
```

**Response (503 Service Unavailable)**

The batch could not be stored; send it again shortly.

```json
{
  "status": "failure",
  "status_code": 503,
  "data": null,
  "request_id": "example",
  "timestamp": 1794214800000,
  "message": "example",
  "errors": {}
}
```

Source: https://developer.watchtower15.com/ingest/reference/logs/
