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

# Read Query

> This API allows for anyone to read the sql text,
parameters, name, tags, and state of a query.
For private queries, only the API key generated
under the context of the owner of that query will work.

<Info>
  Minimum required API key scope: `Read`
</Info>

<Note>
  To access Query endpoints, an [Analyst plan](https://dune.com/pricing) or higher is required.
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl --request GET \
    --url https://api.dune.com/api/v1/query/{queryId} \
    --header 'X-DUNE-API-KEY: <x-dune-api-key>'
  ```

  ```python Python SDK theme={null}
  from dune_client.client import DuneClient

  dune = DuneClient()

  query = dune.get_query(1252207)
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.dune.com/api/v1/query/{queryId}"

  headers = {"X-DUNE-API-KEY": "<x-dune-api-key>"}

  response = requests.request("GET", url, headers=headers)

  print(response.text)

  ```

  ```javascript JavaScript theme={null}
  const options = {method: 'GET', headers: {'X-DUNE-API-KEY': '<x-dune-api-key>'}};

  fetch('https://api.dune.com/api/v1/query/{queryId}', options)
    .then(response => response.json())
    .then(response => console.log(response))
    .catch(err => console.error(err));
  ```

  ```go Go theme={null}
  package main

  import (
  	"fmt"
  	"net/http"
  	"io/ioutil"
  )

  func main() {

  	url := "https://api.dune.com/api/v1/query/{queryId}"

  	req, _ := http.NewRequest("GET", url, nil)

  	req.Header.Add("X-DUNE-API-KEY", "<x-dune-api-key>")

  	res, _ := http.DefaultClient.Do(req)

  	defer res.Body.Close()
  	body, _ := ioutil.ReadAll(res.Body)

  	fmt.Println(res)
  	fmt.Println(string(body))

  }
  ```

  ```php PHP theme={null}
  <?php

  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.dune.com/api/v1/query/{queryId}",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
      "X-DUNE-API-KEY: <x-dune-api-key>"
    ],
  ]);

  $response = curl_exec($curl);
  $err = curl_error($curl);

  curl_close($curl);

  if ($err) {
    echo "cURL Error #:" . $err;
  } else {
    echo $response;
  }
  ```

  ```java Java theme={null}
  HttpResponse<String> response = Unirest.get("https://api.dune.com/api/v1/query/{queryId}")
    .header("X-DUNE-API-KEY", "<x-dune-api-key>")
    .asString();
  ```
</RequestExample>


## OpenAPI

````yaml GET /v1/query/{queryId}
openapi: 3.0.1
info:
  contact: {}
  description: Dune API
  title: DuneAPI
  version: '1.0'
servers:
  - url: https://api.dune.com/api
security: []
paths:
  /v1/query/{queryId}:
    get:
      summary: Returns the details of a query on Dune
      description: |-
        This API allows for anyone to read the sql text,
        parameters, name, tags, and state of a query.
        For private queries, only the API key generated
        under the context of the owner of that query will work.
      parameters:
        - description: API Key for the service
          in: header
          name: X-Dune-Api-Key
          required: true
          schema:
            type: string
        - description: API Key, alternative to using the HTTP header X-Dune-Api-Key
          in: query
          name: api_key
          schema:
            type: string
        - description: Query ID
          in: path
          name: queryId
          required: true
          schema:
            type: integer
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.GetQueryResponse'
          description: OK
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error400'
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error401'
          description: Unauthorized
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error403'
          description: Forbidden
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error404'
          description: Not Found
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error500'
          description: Internal Server Error
components:
  schemas:
    models.GetQueryResponse:
      properties:
        contributors:
          description: |-
            Contributors to the query (users who have created or saved it).
            Only included when include_contributors=true query parameter is set.
          items:
            $ref: '#/components/schemas/models.QueryContributor'
          type: array
        description:
          description: The description of the query
          example: Calculate the average dex volume
          type: string
        is_archived:
          description: |-
            Indicates if the query is archived.
            Archived queries cannot be executed.
          example: false
          type: boolean
        is_private:
          description: Indicates if the query is private.
          example: true
          type: boolean
        is_temp:
          description: Indicates if the query is temporary (unsaved).
          example: false
          type: boolean
        is_unsaved:
          description: Indicates if the query is unsaved (legacy name).
          example: false
          type: boolean
        name:
          description: The name of the query
          example: My Query
          type: string
        owner:
          description: username or team handle
          example: dune
          type: string
        parameters:
          description: The parameters that can modify the execution of the sql.
          items:
            $ref: '#/components/schemas/models.Parameter'
          type: array
        query_engine:
          description: The query engine used to execute the query.
          example: medium
          type: string
        query_id:
          description: The unique ID of the query
          example: 123
          type: integer
        query_sql:
          description: The SQL query text.
          example: SELECT * FROM dex.trades
          type: string
        tags:
          description: Tags associated with the query.
          items:
            type: string
          type: array
        version:
          description: >-
            Version of the query, gets incremented every time the query is
            updated.
          example: 1
          type: integer
      type: object
    models.Error400:
      properties:
        error:
          example: Bad Request
          type: string
      type: object
    models.Error401:
      properties:
        error:
          example: Invalid API Key
          type: string
      type: object
    models.Error403:
      properties:
        error:
          example: >-
            Not allowed to execute query. Query is archived, unsaved or not
            enough permissions
          type: string
      type: object
    models.Error404:
      properties:
        error:
          example: Object not found
          type: string
      type: object
    models.Error500:
      properties:
        error:
          example: Internal error
          type: string
      type: object
    models.QueryContributor:
      properties:
        contribution_count:
          description: The number of contributions this user made to the query
          example: 5
          type: integer
        handle:
          description: The handle (username) of the contributor
          example: wizardofdefi
          type: string
      type: object
    models.Parameter:
      properties:
        description:
          type: string
        enumFromResults:
          $ref: '#/components/schemas/models.EnumFromResults'
        enumOptions:
          items:
            type: string
          type: array
        isFreeformAllowed:
          type: boolean
        isMultiselect:
          type: boolean
        key:
          type: string
        type:
          type: string
        value:
          type: string
        values:
          items:
            type: string
          type: array
      type: object
    models.EnumFromResults:
      properties:
        columnName:
          type: string
        queryId:
          type: integer
      type: object

````