---
title: Read logs with the admin API
project: OpenLogger
version: 1.0
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/openlogger/1-0/reference/read-logs/
updated: 2026-11-19T08:02:31.630Z
---

# Read logs with the admin API

> Query, remove, clear and download logs from a script with the primary access token.

The admin interface reads the logs through `POST /api/`. Your scripts can do the same with the **primary access token**. An API token does not work here.

Every request sends a JSON body with a `schema` that names the action, followed by its arguments as a query string.

## Query logs

```bash
curl -H "x-token: PRIMARY_TOKEN" -H "content-type: application/json" \
  -d '{"schema":"logs?type=error&fields=app,type,message&limit=1"}' \
  https://logs.example.com/api/
```

Response:

```json
{"items":[{"app":"Demo shop","type":"error","message":"Stock check failed for order 1002"}],"count":2,"page":1,"limit":1,"pages":2}
```

`count` is the number of matching logs, `pages` the number of pages.

### Arguments

| Argument | Example | What it does |
|---|---|---|
| a field name | `app=shop` | Filters by `app`, `type`, `schema`, `userid`, `username`, `message`, `url`, `ip`, `ua`, `data` or `id`. Finds the text anywhere in the field and ignores upper and lower case. |
| `dtcreated` | `dtcreated=2026-11-19` | Filters by the day the log arrived. A range: `dtcreated=2026-11-18 - 2026-11-20`. |
| `sort` | `sort=app_asc` | Sorts by a field, `_asc` or `_desc`. The default is `dtcreated_desc`, newest first. |
| `fields` | `fields=app,message` | Returns only these fields. |
| `page` | `page=2` | The page to return. |
| `limit` | `limit=20` | Logs per page, at most 100. |

Each item holds `id`, `app`, `type`, `schema`, `userid`, `username`, `ua`, `message`, `url`, `ip`, `dtcreated` and `data`.

## Remove logs

Pass the IDs of the logs, separated by commas:

```bash
curl -H "x-token: PRIMARY_TOKEN" -H "content-type: application/json" \
  -d '{"schema":"logs_remove?id=24nap001bg51d,24nap002bg50d"}' \
  https://logs.example.com/api/
```

Response:

```json
{"success":true}
```

## Clear all logs

```bash
curl -H "x-token: PRIMARY_TOKEN" -H "content-type: application/json" \
  -d '{"schema":"logs_clear"}' \
  https://logs.example.com/api/
```

Response:

```json
{"success":true}
```

## Download the log file

```bash
curl -H "x-token: PRIMARY_TOKEN" -o logs.nosql https://logs.example.com/api/download/
```

See [Download logs](../../guides/download-logs/) for what the file holds.
