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

# Query data

> Execute an ontology query.



## OpenAPI

````yaml /api-reference/openapi.yml post /query
openapi: 3.0.3
info:
  title: DataLinks
  version: 2.2.3
servers:
  - url: https://api.datalinks.com/api/v1
    description: production server
security:
  - bearerAuth: []
  - openId:
      - implicit
paths:
  /query:
    post:
      tags:
        - query
      summary: Query data
      description: Execute an ontology query.
      operationId: queryData
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/QueryDataRequest'
        required: true
      responses:
        '200':
          $ref: '#/components/responses/QueryResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  schemas:
    QueryDataRequest:
      required:
        - namespace
        - username
      type: object
      properties:
        username:
          type: string
        namespace:
          type: string
        dataset:
          type: string
        query:
          type: string
          default: ''
        naturalLanguageQuery:
          type: string
        model:
          type: string
        provider:
          type: string
        explainRequested:
          type: boolean
    QueryResponseData:
      required:
        - data
        - metadata
      type: object
      properties:
        data:
          $ref: '#/components/schemas/DataArray'
        explainResults:
          $ref: '#/components/schemas/QueryExplainResponse'
        metadata:
          $ref: '#/components/schemas/QueryResponseMetadata'
        resultType:
          $ref: '#/components/schemas/OperationResult'
    ErrorResponse:
      required:
        - error_code
        - message
      type: object
      properties:
        error_code:
          type: string
          example: UNAUTHORIZED
        error_message:
          type: string
          example: ''
        message:
          type: string
          example: Missing authentication token
        sub_errors:
          type: array
          items:
            required:
              - code
              - message
            type: object
            properties:
              code:
                type: string
              message:
                type: string
    DataArray:
      type: array
      description: Array of ontology data objects retrieved from queries.
      items:
        type: object
        additionalProperties: true
    QueryExplainResponse:
      required:
        - children
        - datasetQueriesStat
        - duration
        - id
        - start
      type: object
      properties:
        id:
          type: string
          description: Id of the step.
          example: 930f9d0d-eb0e-4e2f-9b1f-91855efe6b94
        datasetQueriesStat:
          $ref: '#/components/schemas/QueryExplainResponseDatasetQueriesStat'
        start:
          type: string
          description: Timestamp of the step start.
          format: date-time
          example: '2024-03-01T14:30:22.000Z'
        duration:
          type: string
          description: Duration of the step in ISO 8601 format.
          format: duration
          example: PT1M30S
        children:
          type: array
          items:
            $ref: '#/components/schemas/QueryExplainResponse'
      description: Explain results for the query.
    QueryResponseMetadata:
      type: object
      properties:
        count:
          type: integer
          description: Number of results returned.
        executedQuery:
          type: string
          description: The actual query that was executed.
        originalQuery:
          type: string
          description: The original query provided by the user.
        startingDataset:
          type: string
          description: >-
            The initial dataset used when evaluating the query. For linked
            queries, this is the dataset where the query begins.
        finalDataset:
          type: string
          description: >-
            The dataset that the query ultimately returns results from. For
            linked queries, this is the final dataset after following links.
    OperationResult:
      type: string
      description: Type for the result of an operation.
    QueryExplainResponseDatasetQueriesStat:
      required:
        - dataset
        - namespace
        - resultCount
        - username
      type: object
      properties:
        username:
          type: string
          description: Username that dataset belong to
        namespace:
          type: string
          description: Namespace dataset belongs to.
        dataset:
          type: string
          description: Name of dataset.
        resultCount:
          type: integer
          description: Number of results returned from the dataset.
          format: int64
      description: Contains how much data was queried from dataset.
  responses:
    QueryResponse:
      description: Returns query results.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/QueryResponseData'
    Unauthorized:
      description: >-
        Unauthorized. This error occurs if the authentication token is missing
        or invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      description: >
        Use a Bearer token for authentication. Submit the token using the
        `Authorization`

        header: `Authorization: Bearer <token>`.
      scheme: bearer
    openId:
      type: oauth2
      flows:
        implicit:
          authorizationUrl: >-
            https://login.datalinks.com/realms/datalinks-realm/protocol/openid-connect/auth
          scopes:
            openid: openid

````