> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oleria.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get

> Returns a saved query by its id: the stored SQL, the semantic model it targets, and the authorship and version metadata recorded when it was last written. The `version` in the response is what a subsequent update sends as `expected_version`.




## OpenAPI

````yaml /developer-docs/api-reference/trustfusion-openapi-schema-1.0.0.yaml get /v1/query/saved-queries/{query_id}
openapi: 3.0.3
info:
  title: TrustFusion Facets API
  description: >
    API for all facets exposed by TrustFusion, including:


    - **Query**: Validate queries against validation rules, execute governed
    semantic queries

    - **Schema**: Discover semantic models, datasets, fields, relationships, and
    metrics

    - **Threats**: Discover threats and fetch a threat's investigation template
    or advisory by ID


    All endpoints require a valid Cognito JWT token.
  version: 1.0.0
servers:
  - url: https://devx.{environment}.oleria.io
    description: Oleria DevX Server
    variables:
      environment:
        default: prod
        description: Environment name (prod, staging, dev)
        enum:
          - prod
          - staging
          - dev
security:
  - clientCredentials: []
paths:
  /v1/query/saved-queries/{query_id}:
    get:
      tags:
        - Saved Query
      summary: Get
      description: >
        Returns a saved query by its id: the stored SQL, the semantic model it
        targets, and the authorship and version metadata recorded when it was
        last written. The `version` in the response is what a subsequent update
        sends as `expected_version`.
      operationId: GetSavedQuery
      parameters:
        - name: query_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: The opaque saved-query identifier.
          example: 550e8400-e29b-41d4-a716-446655440000
      responses:
        '200':
          description: The saved query.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SavedQuery'
        '401':
          description: Missing or invalid authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Valid token but insufficient permissions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: No saved query with this ID in the tenant.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                code: SAVED_QUERY_NOT_FOUND
                message: Saved query not found
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - clientCredentials:
            - ClientCredentialsResourceServer/client_credentials_base_scope
components:
  schemas:
    SavedQuery:
      type: object
      required:
        - query_id
        - name
        - query_string
        - model
        - created_by
        - last_modified_by
        - version
        - created_at
        - last_modified_at
      description: A stored SQL query with authorship metadata.
      properties:
        query_id:
          type: string
          format: uuid
          description: |
            Opaque stable identifier. Clients key on this, never the name.
          example: 550e8400-e29b-41d4-a716-446655440000
        name:
          type: string
          description: |
            Free-form label, unique within the tenant (case-insensitive).
          example: Disabled MFA accounts
        description:
          type: string
          description: Optional free-form context about the query.
          example: Accounts where MFA is disabled — weekly review
        query_string:
          type: string
          description: The stored SQL text.
          example: >-
            SELECT account_id, mfa_status FROM oleria_account WHERE mfa_status =
            :status
        model:
          type: string
          description: Semantic model the query targets.
          example: oleria_identity
        created_by:
          $ref: '#/components/schemas/Principal'
        last_modified_by:
          $ref: '#/components/schemas/Principal'
        version:
          type: integer
          description: >
            Monotonic version — 1 on create, incremented on every update.
            Doubles as the optimistic-concurrency token on update.
          example: 3
        created_at:
          type: string
          format: date-time
          example: '2026-06-01T10:00:00Z'
        last_modified_at:
          type: string
          format: date-time
          example: '2026-06-04T09:30:00Z'
    ErrorResponse:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: Machine-readable error code for programmatic handling.
          example: QUERY_PARSE_ERROR
        message:
          type: string
          description: Human-readable error description.
          example: Failed to parse SQL query
        details:
          type: object
          additionalProperties: true
          description: Additional context for debugging (optional, free-form).
          example:
            line: 3
            column: 15
            hint: Unexpected token near 'SELCT'
        reasons:
          type: array
          description: >
            Policy violation details. Present when `code` is `POLICY_VIOLATION`.
            Each entry identifies a governance policy that the query violated.
          items:
            $ref: '#/components/schemas/Reason'
    Principal:
      type: object
      required:
        - type
        - id
      description: >
        The principal (user or service client) that created or last modified the
        saved query, identified by a stable, opaque id.
      properties:
        type:
          type: string
          enum:
            - user
            - client
          description: Principal kind.
          example: user
        id:
          type: string
          description: >
            Opaque principal identifier — the `oleriaUserId` for `user`, the
            `client_id` for `client`. Treat as opaque.
          example: ol_a1b2c3d4-e5f6-7890-abcd-ef1234567890
    Reason:
      type: object
      required:
        - code
        - message
      description: A single policy violation identified during query validation.
      properties:
        code:
          type: string
          description: >
            Stable, machine-readable identifier for the denial reason.
            SCREAMING_SNAKE_CASE; declared on the violated policy.
          example: MUTATION_NOT_ALLOWED
        message:
          type: string
          description: Human-readable explanation of the denial.
          example: >-
            Only SELECT queries are permitted. Mutation statements are not
            allowed.
  securitySchemes:
    clientCredentials:
      type: oauth2
      description: >
        OAuth 2.0 Client Credentials flow. The tokenUrl shown is for the
        production environment. For other environments, replace `prod` with the
        target environment name (e.g., `auth.staging.oleria.io` for staging).
      flows:
        clientCredentials:
          tokenUrl: https://auth.prod.oleria.io/oauth/token
          scopes:
            ClientCredentialsResourceServer/client_credentials_base_scope: >-
              Default scope used for all client credentials (RBAC is controlled
              via permissions in the bearer token)

````