openapi: 3.1.0 info: title: Dexwize Query Service version: 1.0.0 description: > Visual queries, saved queries, exports, alerts and a read-only OData v4 feed (E17, ADR-0031). A query is a structured model, never SQL; it compiles only through the TenantQuery whitelist layer, which injects the caller's tenant predicate and binds every value. Pseudonymised and tenant columns are not exposed and application usage is excluded (usage-service enforces k-anonymity there). Every run and export is audited. The /v1 endpoints take a bearer token; the OData feed takes a tenant-scoped API key. security: - bearer: [] paths: /v1/query/datasets: get: summary: Datasets and columns available to the query builder (FindingsRead) operationId: listDatasets responses: '200': description: OK content: application/json: schema: type: array items: $ref: '#/components/schemas/Dataset' '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /v1/query/run: post: summary: Run an ad-hoc query (FindingsRead) operationId: runQuery requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/QuerySpec' responses: '200': description: Rows content: application/json: schema: $ref: '#/components/schemas/QueryResult' '400': description: Unknown dataset or column, bad shape, range over 90 days or limit over the maximum '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /v1/query/saved: get: summary: List saved queries (FindingsRead) operationId: listSavedQueries responses: '200': description: OK content: application/json: schema: type: array items: $ref: '#/components/schemas/SavedQuery' '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } post: summary: Save a query (FindingsRead) operationId: saveQuery requestBody: required: true content: application/json: schema: type: object required: - name - title - spec - windowDays properties: name: type: string pattern: '^[a-z][a-z0-9_]{0,62}$' description: Also the OData entity set name title: type: string maxLength: 200 spec: $ref: '#/components/schemas/QuerySpec' windowDays: type: integer minimum: 1 maximum: 90 description: Each run covers the last windowDays days responses: '201': description: Saved content: application/json: schema: $ref: '#/components/schemas/SavedQuery' '400': description: Invalid name or query '409': description: Name already used in this tenant '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /v1/query/saved/{id}: parameters: - $ref: '#/components/parameters/Id' get: summary: Get a saved query (FindingsRead) operationId: getSavedQuery responses: '200': description: OK content: application/json: schema: $ref: '#/components/schemas/SavedQuery' '404': description: Unknown or another tenant's '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } delete: summary: Delete a saved query (FindingsRead) operationId: deleteSavedQuery responses: '204': description: Deleted '404': description: Unknown or another tenant's '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /v1/query/saved/{id}/run: parameters: - $ref: '#/components/parameters/Id' post: summary: Run a saved query over its rolling window (FindingsRead) operationId: runSavedQuery responses: '200': description: Rows content: application/json: schema: $ref: '#/components/schemas/QueryResult' '404': description: Unknown or another tenant's '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /v1/query/saved/{id}/export: parameters: - $ref: '#/components/parameters/Id' - name: format in: query required: true schema: type: string enum: - csv - parquet get: summary: Export a saved query (ReportsRead; rate limited; capped rows; audited) description: > CSV cells that start with = + - @ tab or carriage return are prefixed with an apostrophe so spreadsheets do not evaluate them. Rows are capped at the TenantQuery maximum. Each export writes an audit entry with the row count. operationId: exportSavedQuery responses: '200': description: File content: text/csv: schema: type: string application/vnd.apache.parquet: schema: type: string format: binary '400': description: Unknown format '404': description: Unknown or another tenant's '429': description: Export rate limit reached '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /v1/query/api-keys: get: summary: List OData API keys without secrets (TenantManage) operationId: listApiKeys responses: '200': description: OK content: application/json: schema: type: array items: $ref: '#/components/schemas/ApiKey' '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } post: summary: Create an OData API key (TenantManage) description: The secret is returned once in this response. Only its SHA-256 hash is stored; it cannot be shown again. operationId: createApiKey requestBody: required: true content: application/json: schema: type: object required: - name properties: name: type: string maxLength: 100 responses: '201': description: Created content: application/json: schema: type: object required: - id - name - prefix - secret properties: id: type: string format: uuid name: type: string prefix: type: string secret: type: string description: Shown once '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /v1/query/api-keys/{id}: parameters: - $ref: '#/components/parameters/Id' delete: summary: Revoke an API key (TenantManage) operationId: revokeApiKey responses: '204': description: Revoked '404': description: Unknown or another tenant's '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /v1/query/alerts: get: summary: List saved-query alerts (FindingsRead) operationId: listQueryAlerts responses: '200': description: OK content: application/json: schema: type: array items: $ref: '#/components/schemas/QueryAlert' '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } post: summary: Create an alert on a saved query measure (TenantManage) description: > When the measure in the first row crosses the threshold, a query_alert event goes to notification-service, which delivers it to the tenant's channels, including signed outbound webhooks. At most one notification per alert per day. operationId: createQueryAlert requestBody: required: true content: application/json: schema: type: object required: - savedQueryId - measure - comparison - threshold properties: savedQueryId: type: string format: uuid measure: type: string description: Alias of a measure in the saved query comparison: type: string enum: - Above - Below threshold: type: number responses: '201': description: Created content: application/json: schema: $ref: '#/components/schemas/QueryAlert' '400': description: Measure is not in the saved query '404': description: Unknown saved query '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /v1/query/alerts/{id}: parameters: - $ref: '#/components/parameters/Id' delete: summary: Delete an alert (TenantManage) operationId: deleteQueryAlert responses: '204': description: Deleted '404': description: Unknown or another tenant's '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /v1/query/alerts/evaluate: post: summary: Evaluate this tenant's alerts now (FindingsRead) operationId: evaluateQueryAlerts responses: '200': description: One result per enabled alert content: application/json: schema: type: array items: type: object properties: alertId: type: string format: uuid fired: type: boolean value: type: - number - 'null' '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /v1/coverage: get: summary: Fleet collection coverage, the gaps agents reported in a window (FindingsRead) description: > Each row is one collector, item and reason with the number of devices that reported it. Agents send a gap at most once a day per collector, item and reason; labels are fixed and never carry paths or error text. operationId: getFleetCoverage parameters: - $ref: '#/components/parameters/CoverageDays' responses: '200': description: OK content: application/json: schema: $ref: '#/components/schemas/FleetCoverage' '400': description: Days outside 1 to 90 /v1/coverage/devices/{deviceId}: get: summary: Collection gaps one device reported in a window (FindingsRead) description: Another tenant's device returns an empty list, never its data. operationId: getDeviceCoverage parameters: - name: deviceId in: path required: true schema: type: string format: uuid - name: days in: query required: false schema: type: integer minimum: 1 maximum: 90 default: 30 responses: '200': description: OK content: application/json: schema: $ref: '#/components/schemas/DeviceCoverage' '400': description: Days outside 1 to 90 /odata/v1/: get: summary: OData v4 service document listing saved queries as entity sets description: > Read-only. Authenticate with the X-Api-Key header (Power BI Web connector) or the api_key query parameter (Excel). The key decides the tenant. In Power BI choose Get Data, OData feed, then the root URL; in Excel choose Data, From OData Feed. operationId: odataServiceDocument security: - apiKey: [] - apiKeyQuery: [] responses: '200': description: Service document content: application/json: schema: type: object properties: '@odata.context': type: string value: type: array items: type: object properties: name: type: string kind: type: string url: type: string '401': description: Missing, unknown or revoked key '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /odata/v1/$metadata: get: summary: CSDL metadata for the saved queries operationId: odataMetadata security: - apiKey: [] - apiKeyQuery: [] responses: '200': description: CSDL XML content: application/xml: schema: type: string '401': description: Missing, unknown or revoked key '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } /odata/v1/{entitySet}: get: summary: Rows of a saved query operationId: odataEntitySet security: - apiKey: [] - apiKeyQuery: [] parameters: - name: entitySet in: path required: true schema: type: string - name: $top in: query schema: type: integer minimum: 1 maximum: 10000 - name: $skip in: query schema: type: integer minimum: 0 responses: '200': description: Rows content: application/json: schema: type: object properties: '@odata.context': type: string value: type: array items: type: object '400': description: $top or $skip out of range '401': description: Missing, unknown or revoked key '404': description: No saved query with this name '403': { $ref: '#/components/responses/FeatureNotEntitled' } '503': { $ref: '#/components/responses/EntitlementsUnavailable' } components: securitySchemes: bearer: type: http scheme: bearer bearerFormat: JWT apiKey: type: apiKey in: header name: X-Api-Key apiKeyQuery: type: apiKey in: query name: api_key parameters: Id: name: id in: path required: true schema: type: string format: uuid CoverageDays: name: days in: query required: false schema: type: integer minimum: 1 maximum: 90 default: 7 responses: FeatureNotEntitled: description: The caller lacks the permission (empty body), or the tenant's plan, add-ons, licence and overrides do not include the feature (error feature_not_entitled, ADR-0053). content: { application/json: { schema: { $ref: '#/components/schemas/EntitlementRefusal' } } } EntitlementsUnavailable: description: The tenant's entitlements could not be confirmed and nothing usable was cached, so the paid feature is refused (fail closed, ADR-0053). Retry-After is set. content: { application/json: { schema: { $ref: '#/components/schemas/EntitlementRefusal' } } } schemas: EntitlementRefusal: description: Module licensing refusal (ADR-0053). type: object required: [error, feature] properties: error: { type: string, enum: [feature_not_entitled, entitlements_unavailable] } feature: { type: string, description: Catalogue feature code, for example query } Dataset: type: object properties: name: type: string columns: type: array items: type: object properties: name: type: string type: type: string numeric: type: boolean time: type: boolean QuerySpec: type: object required: - dataset - from - to properties: dataset: type: string columns: type: array items: type: string measures: type: array items: type: object required: - aggregate - alias properties: aggregate: type: string enum: - Count - Sum - Avg - Min - Max - Uniq - P95 column: type: - string - 'null' alias: type: string pattern: '^[a-z][a-z0-9_]{0,62}$' filters: type: array items: type: object required: - column - op - value properties: column: type: string op: type: string enum: - Eq - NotEq - Gt - Gte - Lt - Lte - In value: description: A scalar, or an array of scalars for In groupBy: type: array items: type: string orderBy: type: array items: type: object properties: output: type: string descending: type: boolean from: type: string format: date-time to: type: string format: date-time description: At most 90 days after from limit: type: integer minimum: 1 maximum: 1000 default: 100 QueryResult: type: object properties: queryId: type: string pattern: '^[0-9a-f]{16}$' description: 'Fingerprint of the query; rows are cited as q:{queryId}#r{n}' columns: type: array items: type: string rows: type: array items: type: object additionalProperties: true truncated: type: boolean SavedQuery: type: object properties: id: type: string format: uuid name: type: string title: type: string spec: $ref: '#/components/schemas/QuerySpec' windowDays: type: integer createdAt: type: string format: date-time createdBy: type: string ApiKey: type: object properties: id: type: string format: uuid name: type: string prefix: type: string createdAt: type: string format: date-time createdBy: type: string revokedAt: type: - string - 'null' format: date-time QueryAlert: type: object properties: id: type: string format: uuid savedQueryId: type: string format: uuid measure: type: string comparison: type: string enum: - Above - Below threshold: type: number enabled: type: boolean createdAt: type: string format: date-time createdBy: type: string FleetCoverageGap: type: object required: [collector, item, reason, devices] properties: collector: type: string item: type: string description: Fixed label for a partial gap inside a collector, or empty for the whole collector reason: type: string enum: [permission_denied, unsupported, broker_unavailable, source_failed] devices: type: integer lastSeen: type: - string - 'null' format: date-time FleetCoverage: type: object required: [days, from, to, devicesWithGaps, gaps] properties: days: type: integer from: type: string format: date-time to: type: string format: date-time devicesWithGaps: type: integer gaps: type: array items: $ref: '#/components/schemas/FleetCoverageGap' DeviceCoverageGap: type: object required: [collector, item, reason, reports] properties: collector: type: string item: type: string description: Fixed label for a partial gap inside a collector, or empty for the whole collector reason: type: string enum: [permission_denied, unsupported, broker_unavailable, source_failed] reports: type: integer firstSeen: type: - string - 'null' format: date-time lastSeen: type: - string - 'null' format: date-time DeviceCoverage: type: object required: [deviceId, days, from, to, gaps] properties: deviceId: type: string format: uuid days: type: integer from: type: string format: date-time to: type: string format: date-time gaps: type: array items: $ref: '#/components/schemas/DeviceCoverageGap'