---
title: "Get SQL for log query"
method: POST
path: "/v1/logs/{log-name}/query-sql"
tags: ["Logs"]
---

# Get SQL for log query

`POST /v1/logs/{log-name}/query-sql`

Build and return the SQL statement that `POST /v1/logs/{log-name}/query` would
execute for the same request body, without running it. Intended for troubleshooting
and for building reports outside of NetXMS.

The statement reflects the caller's object access constraints and includes the row
limit `offset` + `limit`, because paging is done by executing the statement as is
and then skipping the first `offset` records.

## Request body

- LogQueryRequest
  - `filters` LogColumnFilter[] — Column filters combined with AND
    - `column` string — Column to filter on. Required for top level filters, ignored for filters nested in a `set`.
    - `type` 'equals' | 'range' | 'set' | 'like' | 'less' | 'greater' | 'childOf' | 'relative' | 'currentPeriod', required — Filter type. `equals`, `less`, `greater`, and `range` require numeric values; `like` performs an SQL LIKE match (use `%` and `_` as wildcards, empty string matches empty and NULL values); `childOf` matches objects below the given object; `relative` matches a timestamp column within the last N units; `currentPeriod` matches a timestamp column within a calendar period in the client's time zone; `set` combines nested filters on the same column.
    - `negated` boolean — Invert the condition
    - `value` union — Value for `equals`, `less`, `greater`, `childOf` (object ID), `like` (pattern), and `relative` (number of units). String values on numeric columns are parsed as timestamps.
      - integer
      - string
    - `from` union — Lower bound (inclusive) for `range`
      - integer
      - string
    - `to` union — Upper bound (inclusive) for `range`
      - integer
      - string
    - `unit` 'minute' | 'hour' | 'day' | 'week' — Time unit for `relative`
    - `period` 'today' | 'yesterday' | 'thisWeek' | 'thisMonth' — Calendar period for `currentPeriod`
    - `timeZoneOffset` integer — Client UTC offset in seconds (east of UTC) used to resolve `currentPeriod` boundaries
    - `operation` 'and' | 'or' — Operation used to combine nested filters of a `set`
    - `filters` LogColumnFilter[] — Nested filters for `set`
  - `orderBy` object[] — Ordering columns, most significant first
    - `column` string, required — Column to sort by
    - `descending` boolean — Sort in descending order
  - `offset` integer — Number of records to skip
  - `limit` integer — Maximum number of records to return (1 to 10000; `offset` + `limit` may not exceed 100000)

## Response `200`

SQL statement built successfully

- object
  - `query` string — SQL statement in the syntax of the server's database engine

## Other responses

- `400` — Missing request body, invalid filter definition, or invalid offset/limit
- `403` — Access denied (log has an access right requirement not held by the user)
- `404` — Unknown log name

---

[API](https://skmtc.net/netxms/apis/netxms-api.md) · [All operations](https://skmtc.net/netxms/apis/netxms-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/netxms/netxms-api/versions/14d93e5115dd/schema)
