Skip to content

Query API#

The query API lets a program ask Empowerment Center for figures without an interface and with a person's identity: the program sends a cube query and receives the result in JSON, CSV, Excel or Arrow. Use it for automatic reports, loads into other tools or analysis notebooks.

Before you start#

  • The user on whose behalf the query is made needs API and MCP access and Access to Empowerment Center.
  • That user creates a credential with the Query API scope for themselves (see Service credentials).
  • The API comes enabled (ecenter.api.enabled: true). With false, all routes except whoami respond 404 API_DISABLED.

How it works#

  • Never SQL. A cube query (rows, columns, metrics, segmentation) is requested with the catalog identifiers, and ECenter calculates it with the same engine as the cube viewer.
  • With the application's security. The credential acts with all its holder's privileges: their universes limit the rows and what they do not see does not exist for the API. Asking for something hidden responds 403 COLUMNS_HIDDEN with the requested identifiers, never with their names.
  • First it waits, then it works in the background. The request waits up to 10 seconds (up to 30 can be requested). If the query has not finished, it responds 202 with an identifier to follow it.
  • Result in long form. One row per combination of members and one column per metric, easy to load into pandas, Polars, DuckDB or a spreadsheet.

All routes go under /api/query/v1 and carry the header:

Authorization: Bearer ect_…

The session cookie does not work here and the responses create no session. The CSRF token is not needed.

A query through the API Query API sequence: the program reads the catalog, validates the query with the database plan, submits it and receives 202 if it does not finish within the wait, polls until it receives 200 with the first page and downloads the whole CSV without going back to the database. GET /catalog (Bearer ect_…) visible tables, dimensions and metrics POST /queries/validate plan: estimated rows valid, estimate POST /queries?wait=10s job with the holder's identity SQL with their universes 202 {id, status: RUNNING} + Location (or 200 + first page if it finishes earlier) GET /queries/{id}?wait=30s 200 + first page GET /queries/{id}/rows (Accept: text/csv) whole CSV, without going back to the database Program Query API Job queue API class Client database The result lives 30 minutes and only the same credential sees it
A query through the API Query API sequence: the program reads the catalog, validates the query with the database plan, submits it and receives 202 if it does not finish within the wait, polls until it receives 200 with the first page and downloads the whole CSV without going back to the database. GET /catalog (Bearer ect_…) visible tables, dimensions and metrics POST /queries/validate plan: estimated rows valid, estimate POST /queries?wait=10s job with the holder's identity SQL with their universes 202 {id, status: RUNNING} + Location (or 200 + first page if it finishes earlier) GET /queries/{id}?wait=30s 200 + first page GET /queries/{id}/rows (Accept: text/csv) whole CSV, without going back to the database Program Query API Job queue API class Client database The result lives 30 minutes and only the same credential sees it
A query through the API View full size View full size

Routes#

Route What it does
GET /whoami Who the credential is: holder, channel, client, scopes, connections and expiry
GET /connections The connections it can query
GET /connections/{c}/catalog The visible catalog: tables, dimensions, metrics, groupings and lists
POST /connections/{c}/dimensions/{d}/members The members of a dimension, by pages
POST /connections/{c}/queries/validate Validates a query and estimates its rows, without running it
POST /connections/{c}/queries Sends the query: 200 with the first page or 202
POST /connections/{c}/queries/sql The query's SQL, without running it (only with Metadata administration)
GET /queries/{id} The status of a sent query, waiting if requested
GET /queries/{id}/rows A page in JSON, or the whole result in CSV, XLSX or Arrow according to Accept
GET /queries/{id}/explanation The explanation in words: what is calculated, with which filters and which universes limit the rows
DELETE /queries/{id} Cancels the query if it is still running and forgets it
GET /workbooks?connection= The workbooks it can open, with their cube documents and their bookmarks
GET /workbooks/{w}/documents/{d}/query The cube query of a document, ready to send
GET /openapi.json The API contract in OpenAPI 3.1

The full walkthrough#

The examples use curl and assume two environment variables, so that the secret does not stay in the shell history or on the command line:

export ECENTER_URL=https://ecenter.example.org
export ECENTER_API_TOKEN=ect_…        # the credential's secret

The identifiers (305, 1201…) are examples: in your installation they come from the catalog.

1. Check the credential#

curl -s "$ECENTER_URL/api/query/v1/whoami" \
  -H "Authorization: Bearer $ECENTER_API_TOKEN"
{
  "userId": 7,
  "login": "analista",
  "channel": "API",
  "channelRef": "cred:3f0c9a1e-…",
  "credential": "3f0c9a1e-…",
  "clientName": "Informe semanal (Python)",
  "scopes": ["QUERY_API"],
  "connections": [],
  "expiresAt": "2027-01-15T00:00:00Z"
}

An empty connections means “the holder's”. A 401 INVALID_CREDENTIAL here means the credential is not valid: check that it has not expired or been revoked.

2. Choose the connection#

curl -s "$ECENTER_URL/api/query/v1/connections" \
  -H "Authorization: Bearer $ECENTER_API_TOKEN"
[ { "id": "8d6f2c4b-…", "name": "Demo · Distribuciones Ibéricas", "engine": "POSTGRESQL" } ]

The holder's connections appear (the restricted ones, only if they have Metadata administration) and, if the credential is limited to some, only those.

C=8d6f2c4b-…
curl -s "$ECENTER_URL/api/query/v1/connections/$C/catalog?search=importe" \
  -H "Authorization: Bearer $ECENTER_API_TOKEN"
{
  "connection": "8d6f2c4b-…",
  "factTables": [ { "id": 1, "name": "Facturas", "supportsLists": true,
                    "dimensionTables": [1, 2], "metricTables": [1] } ],
  "dimensions": [ { "id": 305, "factTable": 2, "name": "Zona", "type": "LOOKUP_LIST", "codeLength": 1,
                    "hasMembers": true, "segmentable": true, "cubeable": true, "dateLevels": [],
                    "description": "Zona comercial del cliente, según su provincia" } ],
  "metrics": [ { "id": 1201, "factTable": 1, "name": "Importe total", "aggregation": "SUM",
                 "formula": false, "format": "#.##0,00 €" } ],
  "lists": [ { "id": 7, "factTable": 2, "name": "Clientes VIP", "autoRenew": false,
               "renewedAt": "2026-09-28T08:00:00Z" } ],
  "nextCursor": null
}

What is worth knowing about the catalog:

  • What is not here does not exist for the holder. A dimension appears if it is placed in the presentation tree and the holder has its privilege; a metric, if they have its own (a formula, if they also see all its metrics).
  • dimensionTables and metricTables say what combines with what: the metrics of a query have to be able to go together.
  • factTable= keeps only what is used with that table's metrics; search= searches the name and the business description, case-insensitively.
  • hasMembers says whether its members can be requested; dateLevels, the date levels it accepts (YEAR, SEMESTER, QUARTER, MONTH, WEEK).
  • A grouping is one more dimension, of type GROUPING, with its grouped dimension in source and its buckets in buckets.
  • lookupTable, in a lookup dimension, identifies its auxiliary table: two dimensions with the same one have the same codes.
  • Without cursor or limit it arrives whole; with either of them, in pages of 200 elements (up to 1000), first the dimensions, then the metrics and finally the lists. Request the next one with cursor=<nextCursor> and the same factTable and search.

4. Look up the codes of a condition#

To filter by “Zona”, request its members:

curl -s -X POST "$ECENTER_URL/api/query/v1/connections/$C/dimensions/305/members" \
  -H "Authorization: Bearer $ECENTER_API_TOKEN" -H "Content-Type: application/json" \
  -d '{ "search": "nor" }'
{ "members": [ { "code": ["N"], "label": "Norte" } ], "nextCursor": null }
  • In a lookup dimension its values from the auxiliary table appear with their description (label); search searches the description and parent gives the children of a member in a hierarchy.
  • In one that is not a lookup, the distinct values of the records the holder sees appear, with how many records each one has (records); search searches the text as is (% and _ too).
  • In a grouping its buckets appear, with “Other” at the end.
  • code has one part per key column and is used as is in a condition.
  • Pages of 200 members by default, up to 1000.

5. Validate the query#

cat > consulta.json <<'EOF'
{
  "rows": [ { "dimension": 305 } ],
  "columns": [ { "dimension": 310, "dateLevel": "YEAR" } ],
  "metrics": [ { "metric": 1201 }, { "metric": 1201, "display": "PERCENT_OF_TOTAL" } ],
  "segmentation": { "root": { "type": "group", "logic": "AND", "children": [
    { "type": "condition", "dimension": 305, "operator": "IN",
      "values": [ { "type": "literal", "value": "N" }, { "type": "literal", "value": "C" } ] } ] } },
  "totals": true
}
EOF
curl -s -X POST "$ECENTER_URL/api/query/v1/connections/$C/queries/validate" \
  -H "Authorization: Bearer $ECENTER_API_TOKEN" -H "Content-Type: application/json" \
  -d @consulta.json
{ "valid": true, "problems": [], "warnings": [], "hidden": null,
  "estimate": { "rows": 24, "heavy": false, "tooHeavy": false } }

Validating runs nothing: it checks the query against the metadata and asks the database for an estimate of rows. If an identifier does not exist, valid is false and candidates proposes what was probably meant, always from the visible catalog:

"candidates": [ { "kind": "METRIC", "requested": 305,
                  "suggestions": [ { "kind": "DIMENSION", "id": 305, "name": "Zona" } ] } ]

The query body is explained in full in The cube query.

6. Send the query#

curl -s -i -X POST "$ECENTER_URL/api/query/v1/connections/$C/queries?wait=20s" \
  -H "Authorization: Bearer $ECENTER_API_TOKEN" -H "Content-Type: application/json" \
  -d @consulta.json

wait accepts 10, 10s, 500ms or 1m, and is capped at 30 seconds; wait=0 does not wait. There are two possible responses:

200: it has finished and brings the first page (1000 rows by default; limit= up to 10,000):

{
  "id": "qr_Q2hK…", "status": "SUCCEEDED",
  "calculatedAt": "2026-09-25T10:14:03Z", "expiresAt": "2026-09-25T10:44:03Z",
  "columns": [
    { "name": "Zona (código)", "role": "CODE", "dimension": 305, "type": "TEXT" },
    { "name": "Zona", "role": "LABEL", "dimension": 305, "type": "TEXT" },
    { "name": "Año", "role": "CODE", "dimension": 310, "dateLevel": "YEAR", "type": "NUMBER" },
    { "name": "Importe total", "role": "METRIC", "metric": 1201, "display": "VALUE", "type": "NUMBER", "format": "#.##0,00 €" },
    { "name": "Importe total", "role": "METRIC", "metric": 1201, "display": "PERCENT_OF_TOTAL", "type": "NUMBER", "format": "0,00 %" },
    { "name": "Total de", "role": "TOTAL_OF", "type": "IDS" }
  ],
  "rows": [ ["N", "Norte", 2025, 1250340.5, 23.1, null],
            ["C", "Centro", 2025, 980112.0, 18.1, null] ],
  "totalRows": 10, "offset": 0, "nextCursor": null, "truncated": false,
  "hidden": null, "warnings": []
}

With totals: true, the last column (TOTAL_OF) says in each total row which dimensions it aggregates (their codes are null); in data rows it is null. format is the metric's mask in the metadata, or 0,00 % if what is shown is a percentage.

202: it is still being calculated. The response carries the Location header with its address and Retry-After: 1:

{ "id": "qr_Q2hK…", "status": "RUNNING" }

7. Follow a query that takes time#

curl -s "$ECENTER_URL/api/query/v1/queries/qr_Q2hK…?wait=30s" \
  -H "Authorization: Bearer $ECENTER_API_TOKEN"

It responds 200 with the first page as soon as it finishes, or 202 if it is still running after those seconds. Repeat until you get the 200. To drop it, DELETE /queries/{id} cancels it and responds 204.

If the database estimates that the query is heavy, the send (if it knows within its wait) or the follow-up respond 409 HEAVY_QUERY with estimate.rows: decide whether to calculate it anyway by repeating the send with confirmHeavy=true (see Results, limits and errors).

8. Read the rest of the result#

With nextCursor:

curl -s "$ECENTER_URL/api/query/v1/queries/qr_Q2hK…/rows?cursor=<nextCursor>&limit=5000" \
  -H "Authorization: Bearer $ECENTER_API_TOKEN"

Or the whole result in another format, with the Accept header:

# CSV (RFC 4180, UTF-8); delimiter=; for Excel in Spanish
curl -s "$ECENTER_URL/api/query/v1/queries/qr_Q2hK…/rows?delimiter=;" \
  -H "Authorization: Bearer $ECENTER_API_TOKEN" -H "Accept: text/csv" -o resultado.csv

# The pivoted table in Excel, for people
curl -s "$ECENTER_URL/api/query/v1/queries/qr_Q2hK…/rows" \
  -H "Authorization: Bearer $ECENTER_API_TOKEN" \
  -H "Accept: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" -o resultado.xlsx

# Arrow, with the column types (pyarrow, Polars, DuckDB)
curl -s "$ECENTER_URL/api/query/v1/queries/qr_Q2hK…/rows" \
  -H "Authorization: Bearer $ECENTER_API_TOKEN" -H "Accept: application/vnd.apache.arrow.stream" -o resultado.arrows

Paging or downloading does not go back to the database: the result is kept for 30 minutes from when it finishes (expiresAt).

9. Explain the result#

curl -s "$ECENTER_URL/api/query/v1/queries/qr_Q2hK…/explanation" \
  -H "Authorization: Bearer $ECENTER_API_TOKEN"
{
  "summary": "Importe total, Importe total (% del total) por Zona y Año",
  "segmentation": "«Zona» es «N» o «C»",
  "tables": ["Facturas", "Clientes"],
  "universes": [ { "table": "Clientes", "privilege": "Zona Norte", "propagatedTo": "Facturas",
                   "text": "Clientes, por «Zona Norte»; se propaga a Facturas por sus relaciones" } ],
  "hidden": null,
  "notes": ["Solo se cuentan los registros que el usuario puede ver; no se pueden quitar estas restricciones."]
}

The explanation names each universe by its table and by the privilege through which the holder has it, never by its condition. Use it to state, next to the figures, what limits them. The texts of the explanation come from the server; in this example they are in Spanish.

Start from a document#

A cube document of a workbook has already been reviewed by someone: it is usually a better starting point than a query written from scratch.

  1. GET /workbooks?connection=<c>&search=<text> gives the workbooks the holder can open with their cube documents and their bookmarks.
  2. GET /workbooks/{w}/documents/{d}/query?bookmark=<bookmark> returns the document's query, restricted to what the holder sees and trimmed to their data. What was removed is counted in hidden and trimmed, never named.
  3. Send it as is, or send a query with from to change something (see The cube query).

See the SQL#

POST /connections/{c}/queries/sql, with the same query, returns the SQL that would be run and its parameters, without running it, like the application's Show SQL. It also requires Metadata administration. The SQL carries the conditions of the holder's universes. Period comparisons and compound queries do not have a single SQL and respond 400.

The sample client#

The repository includes a dependency-free Python client that goes through the whole API: tools/demo-data/api_example.py. It reads the secret from the ECENTER_API_TOKEN variable:

export ECENTER_URL=https://ecenter.example.org ECENTER_API_TOKEN=ect_…
python3 tools/demo-data/api_example.py --metric "Importe total" --rows Zona \
    --columns "Fecha de factura" --date-level YEAR --async --out /tmp/resultado

It checks the credential, chooses the metric and the dimensions by name, validates, sends (with --async, without waiting, and follows the 202), goes through the pages, requests the explanation and downloads the CSV, the XLSX and the Arrow.

Audit#

Each query run or rejected is recorded in the audit with the API channel and the cred:<id> reference of the credential. Validating, reading the catalog and listing workbooks are not audited. See Audit.

See also#