query🔎

The Query API allows for parameterised queries from cached templates to be sent to a database connection defined in the process environment.

%{id} parameter prefixed with % will be provided as an array with the query.

${table} parameter prefixed with $ will substituted in the template before the query is sent to the DBS connection. Parameter values wich are substituted may only contain a set of whitelisted characters !/^[A-Za-z0-9,"'._-]*$/.test().

Roles will be checked against the user if a layer parameter is provided.

The ${filter} parameter will be substituted with a SQL filter generated by the sqlFilter module.

In order to make a request to the query endpoint you will need to provide an api token in the query params of the request.

Example of a query with an api token as a param

/api/query?locale=locale_name&layer=layer_name&template=template_name&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

Endpoint : /api/query

params :

  • locale: LOCALE_KEY - Required
  • layer: LAYER_KEY - Required
  • template: TEMPLATE_KEY - required
  • token: API_KEY - required if making a request as a 3rd party api call
  • dbs: DBS_KEY - required if not set in workspace

The response of a query will typically result in a text/json response.

Example Response

[
    {
        "Postal Sector": "Grand Total",
        "Total HHs": null,
        "Deliverable HHs": null,
        "% Deliverable HHs": null,
        "Target HHs": null
    },
    {
        "Postal Sector": null,
        "Total HHs": null,
        "Deliverable HHs": null,
        "% Deliverable HHs": null,
        "Target HHs": "0"
    }
]

All status codes are defined by RFC 9110