For the complete documentation index, see llms.txt. This page is also available as Markdown.

Query API

Save, validate, and execute queries from your own code.

Your goal

Run and manage queries programmatically - and save them as objects when another platform feature needs to reference one.

Expected outcome

Queries you can check before saving, saved queries other objects can point at, and executions whose caching behaviour you control.

When a query has to be saved

You usually type OTQL queries directly into tools such as Navigator. But queries can be saved and managed by code as objects, and some features require you to link an object to a saved query rather than to query text:

Feature
Why it needs a saved query

An export definition references a query_id.

Each metric references a query_id.

Cards reference queries.

Features that ask you to save a query usually do so to optimise performance.

Check a query before you save it

POST https://api.mediarithmics.com/v1/datamarts/:datamartId/query_check/otql
{ "query": "SELECT {id} FROM UserPoint" }

A valid query returns type: "VALID". An invalid one returns type: "PARSING_ERROR" with a message, the row and column of the problem, and an error type:

Save a query

The response returns the query object, including the id you use in the next steps:

An invalid query is rejected with BAD_REQUEST_DATA and the parsing error - you cannot save an invalid query.

Execute a query

The body is the OTQL query as a string.

Fields worth reading beyond rows:

Field
What it tells you

took

Execution time.

timed_out

Whether the query completed.

result_type

The kind of result - COUNT, and so on.

precision, sampling_ratio

Whether the answer is exact.

cache_hit

Whether the response came from the cache.

A 503 with SERVICE_UNAVAILABLE means retry later - worth handling explicitly in an automated job.

Caching

use_cache=true returns the cached result when one is available; check cache_hit to know whether it did. The cache expires after 12 hours.

Without the parameter, or with false, the cache is skipped: the query runs and its result is not stored. You cannot use this to force a cache refresh.

For GraphQL

The GraphQL endpoint is separate, and covered in GraphQL queries:

Last updated

Was this helpful?