---
title: "Ingest events"
---

> Documentation Index
> Fetch the complete documentation index at: https://sandrinodm.github.io/logbrook/llms.txt
> Use this file to discover all available pages before exploring further.

# Ingest events

Path: Logbrook API › Logs

`POST /indexes/{index}/logs/ingest`

The batch is atomic: every event is stored or none is. Event times must fall between now minus the retention period and now plus the allowed future skew (five minutes by default). Producer fields that Logbrook doesn't map are kept in `attributes`. The first authorized write to a missing index creates it, up to `max_indexes`.

## Authentication

- `bearerAuth`, http, header `Authorization`

## Path parameters

- `index` (`ingestLogs.path.index`; string, required) — Index name: lowercase letters, digits, underscores and hyphens. The token's index scope applies as well as its source scope.
  - minLength 1; maxLength 63; pattern `^[a-z0-9][a-z0-9_-]*$`

## Request body (application/json)

_Required._

- `time` (`ingestLogs.time`; integer, required) — Unix milliseconds
  - min 0
- `level` (`ingestLogs.level`; integer, required)
  - min 0
- `msg` (`ingestLogs.msg`; string, required)
- `service` (`ingestLogs.service`; string | null, optional)
- `name` (`ingestLogs.name`; string | null, optional)
- `hostname` (`ingestLogs.hostname`; string | null, optional)
- `pid` (`ingestLogs.pid`; integer | null, optional)
  - min 0

## Example request

```json
[
  {
    "time": 1794297417000,
    "level": 30,
    "msg": "payment authorized",
    "service": "checkout-api",
    "name": "payments",
    "hostname": "web-1",
    "pid": 4182,
    "orderId": "ord_8f3k2",
    "amountCents": 4999,
    "currency": "EUR"
  },
  {
    "time": 1794297418500,
    "level": 40,
    "msg": "card issuer slow to respond",
    "service": "checkout-api",
    "name": "payments",
    "hostname": "web-1",
    "pid": 4182,
    "orderId": "ord_8f3k3",
    "latencyMs": 2380
  },
  {
    "time": 1794297421200,
    "level": 50,
    "msg": "payment declined",
    "service": "checkout-api",
    "name": "payments",
    "hostname": "web-2",
    "pid": 3920,
    "orderId": "ord_8f3k4",
    "reason": "insufficient_funds"
  }
]
```

## Request body (application/x-ndjson)

### Example

```json
"{\"time\":1794297417000,\"level\":30,\"msg\":\"payment authorized\",\"service\":\"checkout-api\",\"name\":\"payments\",\"hostname\":\"web-1\",\"pid\":4182,\"orderId\":\"ord_8f3k2\",\"amountCents\":4999,\"currency\":\"EUR\"}\n{\"time\":1794297418500,\"level\":40,\"msg\":\"card issuer slow to respond\",\"service\":\"checkout-api\",\"name\":\"payments\",\"hostname\":\"web-1\",\"pid\":4182,\"orderId\":\"ord_8f3k3\",\"latencyMs\":2380}\n{\"time\":1794297421200,\"level\":50,\"msg\":\"payment declined\",\"service\":\"checkout-api\",\"name\":\"payments\",\"hostname\":\"web-2\",\"pid\":3920,\"orderId\":\"ord_8f3k4\",\"reason\":\"insufficient_funds\"}\n"
```

## Code samples

### cURL

```bash
curl --request POST \
  --url '<base-url>/indexes/payments/logs/ingest' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
[
  {
    "time": 1794297417000,
    "level": 30,
    "msg": "payment authorized",
    "service": "checkout-api",
    "name": "payments",
    "hostname": "web-1",
    "pid": 4182,
    "orderId": "ord_8f3k2",
    "amountCents": 4999,
    "currency": "EUR"
  },
  {
    "time": 1794297418500,
    "level": 40,
    "msg": "card issuer slow to respond",
    "service": "checkout-api",
    "name": "payments",
    "hostname": "web-1",
    "pid": 4182,
    "orderId": "ord_8f3k3",
    "latencyMs": 2380
  },
  {
    "time": 1794297421200,
    "level": 50,
    "msg": "payment declined",
    "service": "checkout-api",
    "name": "payments",
    "hostname": "web-2",
    "pid": 3920,
    "orderId": "ord_8f3k4",
    "reason": "insufficient_funds"
  }
]
'
```

### TypeScript

```typescript
const url = '<base-url>/indexes/payments/logs/ingest';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify([
    {
      time: 1794297417000,
      level: 30,
      msg: 'payment authorized',
      service: 'checkout-api',
      name: 'payments',
      hostname: 'web-1',
      pid: 4182,
      orderId: 'ord_8f3k2',
      amountCents: 4999,
      currency: 'EUR'
    },
    {
      time: 1794297418500,
      level: 40,
      msg: 'card issuer slow to respond',
      service: 'checkout-api',
      name: 'payments',
      hostname: 'web-1',
      pid: 4182,
      orderId: 'ord_8f3k3',
      latencyMs: 2380
    },
    {
      time: 1794297421200,
      level: 50,
      msg: 'payment declined',
      service: 'checkout-api',
      name: 'payments',
      hostname: 'web-2',
      pid: 3920,
      orderId: 'ord_8f3k4',
      reason: 'insufficient_funds'
    }
  ])
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "<base-url>/indexes/payments/logs/ingest"

payload = [
    {
        "time": 1794297417000,
        "level": 30,
        "msg": "payment authorized",
        "service": "checkout-api",
        "name": "payments",
        "hostname": "web-1",
        "pid": 4182,
        "orderId": "ord_8f3k2",
        "amountCents": 4999,
        "currency": "EUR"
    },
    {
        "time": 1794297418500,
        "level": 40,
        "msg": "card issuer slow to respond",
        "service": "checkout-api",
        "name": "payments",
        "hostname": "web-1",
        "pid": 4182,
        "orderId": "ord_8f3k3",
        "latencyMs": 2380
    },
    {
        "time": 1794297421200,
        "level": 50,
        "msg": "payment declined",
        "service": "checkout-api",
        "name": "payments",
        "hostname": "web-2",
        "pid": 3920,
        "orderId": "ord_8f3k4",
        "reason": "insufficient_funds"
    }
]
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

Successful response

#### Example

```json
{
  "accepted": 3
}
```

- `accepted` (`ingestLogs.response.200.accepted`; integer, required)
  - min 0

### 400

Invalid input

#### Example

```json
{
  "error": "event 0: time must be integer Unix milliseconds"
}
```

- `error` (`ingestLogs.response.400.error`; string, required)

### 401

Missing or invalid token

#### Example

```json
{
  "error": "Bearer token required"
}
```

- `error` (`ingestLogs.response.401.error`; string, required)

### 403

Source outside read scope

#### Example

```json
{
  "error": "index outside token scope"
}
```

- `error` (`ingestLogs.response.403.error`; string, required)

### 404

Index not found

#### Example

```json
{
  "error": "unknown index"
}
```

- `error` (`ingestLogs.response.404.error`; string, required)

### 413

Payload exceeds configured budget

#### Example

```json
{
  "error": "request body exceeds limit"
}
```

- `error` (`ingestLogs.response.413.error`; string, required)

### 429

Capacity exhausted; Retry-After: 1

#### Example

```json
{
  "error": "storage queue full"
}
```

- `error` (`ingestLogs.response.429.error`; string, required)

### 503

Storage unavailable

#### Example

```json
{
  "error": "storage unavailable"
}
```

- `error` (`ingestLogs.response.503.error`; string, required)

### 504

Query deadline expired

#### Example

```json
{
  "error": "request body receive deadline exceeded; nothing admitted"
}
```

- `error` (`ingestLogs.response.504.error`; string, required)

### 507

The index's disk-size budget is exhausted. The oldest history may be reclaimed before later requests are accepted.

#### Example

```json
{
  "error": "index size retention target has no safe disk headroom; retry after retention or increase the target; an unreclaimable DuckDB file may require an offline rebuild"
}
```

- `error` (`ingestLogs.response.507.error`; string, required)


Source: https://sandrinodm.github.io/logbrook/api/logs/ingest/index.md
