Meet Toki Operator

Docs/Manage API

SQL reporting

Analytical reports, top customer rankings, sales summaries and reporting dataset descriptions.

Use reportingCatalog to discover the allowed reporting views and their columns before writing SQL. For top-N rankings, counts, totals and grouped summaries, prefer reportingRunSql when the datasets support the requested metrics. Filter, aggregate, sort and limit results on the server. SQL queries are scoped to the current merchant. Both operations require custom SQL reporting to be enabled for the merchant and a full-access merchant role.

query

reportingCatalog#

Discover datasets for analytical reports, top customers ranked by points balances, sales summary reports, loyalty reports and grouped summaries. Inspect this catalog before using reportingRunSql to aggregate orders or customer data: it returns the allowed SQL views with dataset and column descriptions, PostgreSQL types and nullability. Check that these views support the requested metrics; do not invent tables or columns. Requires custom SQL reporting to be enabled for the merchant and a full-access merchant role.

Returns

[TokiReportingCatalogPayload!]!

An allowed reporting view scoped to the current merchant.

  • nameString!

    View name in the reporting schema; use this name in FROM and JOIN clauses.

  • descriptionString!

    The data represented by this reporting view.

  • columns[TokiReportingCatalogPayloadColumns!]!

    Columns available in this reporting view.

query ReportingCatalog {
  reportingCatalog {
    name
    description
    columns {
      name
      databaseType
      nullable
      description
    }
  }
}
Response
{
  "data": {
    "reportingCatalog": [
      {
        "name": "Gold",
        "description": "Earn double points on every order in July.",
        "columns": [
          {
            "name": "Gold",
            "databaseType": "Database type",
            "nullable": false,
            "description": "Earn double points on every order in July."
          }
        ]
      }
    ]
  }
}
mutation

reportingRunSql#

Build analytical reports with one read-only SQL SELECT: aggregate orders and customer data, calculate counts and totals, join reporting views, produce a sales summary or loyalty report, and rank top customers by points balances when the available datasets support those metrics. Discover views, column meanings and types with reportingCatalog first. Use SQL WHERE, GROUP BY, ORDER BY and LIMIT for server-side filtering, grouped summaries and top-N rankings instead of fetching every customer through users and sorting locally. Queries are scoped to the current merchant, including its shops; add a shop filter when the requested report is for one shop and the dataset supports it. Returns at most 1,000 rows with a 15-second statement timeout. Although exposed as a GraphQL mutation, this operation does not modify merchant data. Requires custom SQL reporting to be enabled for the merchant and a full-access merchant role.

Input

TokiReportingRunSqlInput!

SQL query to execute within the current merchant's reporting scope.

  • sqlString!Required

    One read-only PostgreSQL SELECT statement using views from reportingCatalog. View names may be unqualified or prefixed with reporting. Other schemas and write statements are not allowed.

Returns

TokiReportingRunSqlPayload!

SQL reporting result or validation and execution errors.

  • resultTokiReportingRunSqlResult

    The SQL result, or null when execution failed.

  • errors[TokiReportingRunSqlErrors!]!

    Reporting errors; empty on success.

mutation ReportingRunSql($input: TokiReportingRunSqlInput!) {
  reportingRunSql(input: $input) {
    result {
      rows
      rowCount
      truncated
      durationMs
      columns {
        name
        databaseType
      }
    }
    errors {
      code
      message
    }
  }
}
Variables
{
  "input": {
    "sql": "Sql"
  }
}
Response
{
  "data": {
    "reportingRunSql": {
      "result": {
        "rows": [
          {}
        ],
        "rowCount": 3,
        "truncated": false,
        "durationMs": 1,
        "columns": [
          {
            "name": "Gold",
            "databaseType": "Database type"
          }
        ]
      },
      "errors": [
        {
          "code": "INVALID_SQL",
          "message": "Message"
        }
      ]
    }
  }
}