---
title: "Create a site's saved log query"
url: https://docs.corefinity.com/api/reference/logs/create-site-log-saved-query
type: endpoint
last_updated: 2026-11-13
feature: logs
related:
  - https://docs.corefinity.com/guides/sites/logs-and-monitoring/logs.md
  - https://docs.corefinity.com/mcp/tools/corestack_logs_saved_query_create.md
---
# Create a site's saved log query

Saves a query, filters or neither with a source and a time range: for this site when `site_id` is sent, for
every site otherwise. You can keep 50 saved queries.

```http
POST /api/corestack/sites/{site}/logs/saved-queries
```

- Scope: `write`
- Two-factor: required on your account (all)
- Rate limit: 30 a minute
- Try it in the console: on

## Path parameters

- `site` (integer, required): The id of a site row. A website's production site and each of its environments has its own id. Digits only.

## Body

- `filters` (object or any or null): Filters, kept with the query.
- `name` (string, required)
- `query` (string or null): A LogsQL query. Up to 4 KB.
- `range` (string, required): The time range the query opens with. `custom` means a range chosen each time. One of `15m`, `1h`, `6h`, `24h`, `7d`, `30d`, `custom`.
- `source` (string, required): A log source. `all` reads every source. `search` and `queue` exist only on platforms that run them; the sources list says which ones an environment has. One of `all`, `web-access`, `web-error`, `php`, `app`, `cron`, `database`, `cache`, `search`, `queue`. Defaults to `all`.
- `site_id` (integer or null): The `{site}` of the request, to keep the query for this site. Left out or null, the query is kept for every site.

## Request

### curl

```bash
curl -X POST https://manage.corefinity.com/api/corestack/sites/1042/logs/saved-queries \
  -H "Authorization: Bearer $COREFINITY_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "filters": {
      "level": [
        "warning",
        "error"
      ]
    },
    "name": "PHP warnings",
    "range": "7d",
    "source": "php"
  }'
```

### PHP

```php
use Illuminate\Support\Facades\Http;

$response = Http::withToken(env('COREFINITY_TOKEN'))
    ->acceptJson()
    ->post('https://manage.corefinity.com/api/corestack/sites/1042/logs/saved-queries', [
        'filters' => [
            'level' => [
                'warning',
                'error',
            ],
        ],
        'name' => 'PHP warnings',
        'range' => '7d',
        'source' => 'php',
    ]);

$data = $response->json();
```

### Node

```javascript
const res = await fetch('https://manage.corefinity.com/api/corestack/sites/1042/logs/saved-queries', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.COREFINITY_TOKEN}`,
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filters: {
      level: [
        'warning',
        'error',
      ],
    },
    name: 'PHP warnings',
    range: '7d',
    source: 'php',
  }),
});

// An answer with no body (204) has nothing to parse.
const text = await res.text();
const data = text && JSON.parse(text);
```

### Python

```python
import os
import requests

res = requests.post(
    "https://manage.corefinity.com/api/corestack/sites/1042/logs/saved-queries",
    headers={
        "Authorization": f"Bearer {os.environ['COREFINITY_TOKEN']}",
        "Accept": "application/json",
    },
    json={
        "filters": {
            "level": [
                "warning",
                "error",
            ],
        },
        "name": "PHP warnings",
        "range": "7d",
        "source": "php",
    },
)

data = res.json() if res.content else None
```

## Responses

### 201 The saved query.

```json
{
  "can_delete": true,
  "created_at": "2026-11-03T10:00:00Z",
  "filters": null,
  "id": 3318,
  "name": "Checkout errors",
  "query": "status:>=500",
  "range": "24h",
  "shared": false,
  "site": {
    "domain": "harbourandfinch.example.com",
    "id": 1042
  },
  "source": "web-access"
}
```

### 401 No token, or a token that is not valid.

```json
{
  "message": "Unauthenticated."
}
```

### 403 The token lacks the scope (`scope_required`, with the `scope` to use), or your company requires two-factor authentication and you have not set it up. For routes outside Managed Clusters.

```json
{
  "code": "company_unavailable",
  "message": "Your company is unavailable.",
  "reason": "company_unavailable"
}
```

### 404 The id does not exist or is something you cannot see, or the feature is not on for your company (`feature_off`).

```json
{
  "code": "feature_off",
  "message": "Not found.",
  "reason": "feature_off"
}
```

### 422 A field is missing or wrong. `field` names the first one and `errors` lists every one. Beside the request's own fields, `errors` can name `query` (the LogsQL is not valid, is over 4 KB, uses the `stream_context` pipe or the `time_offset` option, or is an aggregating query sent to an export), `filters.<name>` (a filter is not valid), `filters_max` (too many text or field filters), `cursor` (the cursor is not this request's or this token's) and `saved_max` (you already keep 50 saved queries).

```json
{
  "code": "invalid",
  "errors": {
    "query": [
      "Keep the query under 4 KB."
    ]
  },
  "field": "query",
  "message": "Keep the query under 4 KB.",
  "reason": "invalid"
}
```

### 429 Too many requests (`rate_limited`). Wait for the number of seconds in `Retry-After`, which `retry_after_seconds` repeats.

```json
{
  "code": "rate_limited",
  "message": "Too many requests. Try again in 60 seconds.",
  "reason": "rate_limited",
  "retry_after_seconds": 60
}
```

## If it is refused

| Status | Reason | What to do |
|---|---|---|
| 401 |  | Send a valid token as `Authorization: Bearer <token>`. |
| 403 | `company_unavailable` | Your company is unavailable. |
| 403 | `scope_required` | Use a token with the scope named in `scope`. |
| 403 | `two_factor_required` | Turn on two-factor on your account, then send again. |
| 404 | `feature_off` | This feature is not on for your organisation yet. |
| 422 | `invalid` | Fix the field named in `field`; `errors` says why. |
| 429 | `rate_limited` | Wait for the seconds in `Retry-After`. |

## The same task elsewhere

- Guide: [Logs](https://docs.corefinity.com/guides/sites/logs-and-monitoring/logs.md)
- MCP tool: [`corestack_logs_saved_query_create`](https://docs.corefinity.com/mcp/tools/corestack_logs_saved_query_create.md)
