> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bloklake.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Register a prepared query

> POST /v1/queries: register a filter and get its id without running it.

```http theme={null}
POST https://api.bloklake.com/v1/chains/{chain}/v1/queries
Authorization: Bearer <key>
Content-Type: application/json
```

Every query you run is registered automatically, and its id is in every response
(`bl.query_id_template`). Use this endpoint only if you want the id before running anything. See
[Prepared queries](https://docs.bloklake.com/querying/prepared-queries.md).

## Body

A query body without the range: `logs`, `transactions`, `fields`, `joinTransactions`,
`blockInterval`, `blockOffset`. With `strictFields: true`, a field this chain doesn't have is a
`400` here too (the prepared query itself isn't strict). See [Query](https://docs.bloklake.com/api-reference/query.md).

## Example

```bash theme={null}
curl https://api.bloklake.com/v1/chains/eth/v1/queries \
  -H "Authorization: Bearer $BLOKLAKE_API_KEY" -H 'content-type: application/json' \
  -d '{"logs": [{"topic0": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}],
       "fields": {"log": {"address": true}}}'
```

```json theme={null}
{"query_id": "0xfee8ff0ddc7103d2f35bbc5bc6c6c90253ed493b1247c12fc47b425163b6a0a0", "expires_in": 1800}
```

## Response

**query\_id** `string`

The template's id: send it as `queryId` with `fromBlock`, `toBlock`, `maxObjects` and `strictFields`.

**expires\_in** `integer`

Seconds until it expires if unused. Each use restarts the timer.

## Using it

```json theme={null}
{"queryId": "0xfee8ff0ddc7103d2f35bbc5bc6c6c90253ed493b1247c12fc47b425163b6a0a0", "fromBlock": 19426000, "toBlock": 19426099}
```

When the server answers `400 unknown_query_id` (expired, or another chain), send the full body
again.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.