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

# Save SQL as a query

> Save Trino SQL you wrote as a data engineering query you own, without
running the crew. The SQL is previewed first; nothing is saved if it
fails.



## OpenAPI

````yaml post /api/dataeng/query
openapi: 3.1.0
info:
  title: Nx1 AI API
  description: |

    AI API for Nx1 Data Platform Management and Automated Data Tasks.

    Authentication is required via PSK in Authorization header.

    Default PSK is | [ask a friend] |
  version: 0.10.2
servers: []
security: []
paths:
  /api/dataeng/query:
    post:
      tags:
        - Data engineering
      summary: Save SQL as a query
      description: |-
        Save Trino SQL you wrote as a data engineering query you own, without
        running the crew. The SQL is previewed first; nothing is saved if it
        fails.
      operationId: create_query_api_dataeng_query_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateDataEngQueryRequest'
        required: true
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataEngRevision'
        '422':
          description: The SQL does not run.
      security:
        - OAuth2AuthorizationCodeBearer: []
        - APIKeyHeader: []
components:
  schemas:
    CreateDataEngQueryRequest:
      properties:
        job_name:
          type: string
          maxLength: 120
          minLength: 1
          title: Job Name
        sql:
          type: string
          minLength: 1
          title: Sql
          description: Trino SQL — a SELECT.
        federated:
          type: boolean
          title: Federated
          description: Run on Trino across catalogs, instead of on Spark.
          default: false
      type: object
      required:
        - job_name
        - sql
      title: CreateDataEngQueryRequest
      description: Save SQL you wrote as a query, without running the crew.
    DataEngRevision:
      properties:
        id:
          type: string
          format: uuid
          title: Id
        query:
          type: string
          title: Query
          description: The SQL now stored.
        editable_sql:
          type: string
          title: Editable Sql
        preview:
          anyOf:
            - $ref: '#/components/schemas/DataResponse'
            - type: 'null'
        jobs_updated:
          items:
            $ref: '#/components/schemas/DataEngScheduledJob'
          type: array
          title: Jobs Updated
          description: Scheduled jobs whose DAG now runs the new SQL.
        jobs_failed:
          items:
            $ref: '#/components/schemas/DataEngScheduledJob'
          type: array
          title: Jobs Failed
          description: >-
            Scheduled jobs still running the OLD SQL because their DAG could not
            be rewritten.
      type: object
      required:
        - id
        - query
        - editable_sql
      title: DataEngRevision
      description: The outcome of editing a data-engineering query.
    DataResponse:
      properties:
        start:
          type: integer
          title: Start
          description: >-
            The starting offset for pagination when returning a subset of the
            dataset.
        row_count:
          type: integer
          title: Row Count
          description: The number of rows included in the current response.
        next_start:
          anyOf:
            - type: integer
            - type: 'null'
          title: Next Start
          description: >-
            The offset value for the next page of data, if additional results
            are available.
        columns:
          items:
            type: string
          type: array
          title: Columns
          description: >-
            A list of column names representing the structure of the returned
            dataset.
        data:
          anyOf:
            - items:
                items: {}
                type: array
              type: array
            - type: 'null'
          title: Data
          description: >-
            The actual tabular data returned, where each inner list represents a
            row of values.
      type: object
      required:
        - start
        - row_count
        - columns
      title: DataResponse
    DataEngScheduledJob:
      properties:
        job_id:
          type: string
          format: uuid
          title: Job Id
        job_name:
          type: string
          title: Job Name
        schedule:
          anyOf:
            - type: string
            - type: 'null'
          title: Schedule
        airflow_url:
          anyOf:
            - type: string
            - type: 'null'
          title: Airflow Url
        error:
          anyOf:
            - type: string
            - type: 'null'
          title: Error
          description: Why the job's DAG could not be updated, if it failed.
      type: object
      required:
        - job_id
        - job_name
      title: DataEngScheduledJob
      description: A scheduled job that runs a data-engineering query.
  securitySchemes:
    OAuth2AuthorizationCodeBearer:
      type: oauth2
      flows:
        authorizationCode:
          scopes: {}
          authorizationUrl: >-
            https://sso-rapid.rapid.nx1cloud.com/realms/rapid/protocol/openid-connect/auth
          tokenUrl: >-
            https://sso-rapid.rapid.nx1cloud.com/realms/rapid/protocol/openid-connect/token
    APIKeyHeader:
      type: apiKey
      in: header
      name: Authorization-PSK

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.