Run a custom query over your request logs
const url = 'https://api.nsin.ir/analytics/query';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"sql":"SELECT toStartOfHour(event_time) AS h, count() AS c FROM requests WHERE status >= 500 GROUP BY h ORDER BY h"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.nsin.ir/analytics/query \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "sql": "SELECT toStartOfHour(event_time) AS h, count() AS c FROM requests WHERE status >= 500 GROUP BY h ORDER BY h" }'Runs a read-only SQL SELECT against the requests table — your raw
request log — for analyses the dedicated endpoints do not cover.
Scoping is enforced by the database engine, not by your query: a
filter restricting rows to the domains this key can access is appended
to every read of requests. You cannot read another account’s traffic,
however the query is written.
Restrictions:
- A single statement only, starting with
SELECTorWITH. - Only the
requeststable may be read. Common table expressions you define yourself are fine; other tables and anydb.tablereference are rejected. - Writes, DDL and settings changes are rejected.
- Execution is capped at 30 seconds and 10 000 returned rows —
truncatedtells you when the cap was hit.
Useful requests columns: event_time, domain_id, hostname,
method, uri, status, bytesIn, bytesOut, duration (ms),
remoteAddr, country, asn, asnOrg, userAgent, cacheStatus,
reqStatus, isWS, protocol, referer, originStatus,
originAddr, error.
Authorizations
Section titled “Authorizations ”Request Body required
Section titled “Request Body required ”object
The query to run.
Responses
Section titled “ Responses ”Query result.
object
Column names, in result order.
One entry per row, keyed by column name.
object
True when the 10 000-row cap was reached and results were cut short.
Example generated
{ "columns": [ "example" ], "rows": [ {} ], "row_count": 1, "truncated": true}The query was rejected by validation, or the database refused it.
detail carries the underlying message when the engine rejected it.
object
Examples
{ "error": "querying \"system.parts\" is not allowed; only the 'requests' table may be read"}Missing, malformed, revoked or expired API key — or the owning account is inactive.
The single error shape used by every endpoint.
object
Human-readable description of what went wrong.
Examples
{ "error": "invalid API key"}Read-only key, or the account has no domains whose logs could be queried.
The single error shape used by every endpoint.
object
Human-readable description of what went wrong.
Example
{ "error": "read-only API key"}The key exceeded its request budget (300 requests per minute by default).
The single error shape used by every endpoint.
object
Human-readable description of what went wrong.
Examples
{ "error": "rate limit exceeded"}The analytics backend is temporarily unreachable. Retry; no data is lost.
The single error shape used by every endpoint.
object
Human-readable description of what went wrong.
Examples
{ "error": "analytics unavailable"}