curl -X POST "https://api.dune.com/api/v1/query/{{query_id}}/execute" \
-H "X-Dune-API-Key: {{api_key}}" \
-H "Content-Type: application/json" \
-d '{"query_parameters": {"param1":24}, "performance": "large"}'
'''
Download Dune Python SDK by running `pip install dune-client`
For more info, visit the GitHub repository: https://github.com/duneanalytics/dune-client/tree/d2195b2a9577e2dcae5d2600cb3eddce20987f38
'''
import json
from dune_client.types import QueryParameter
from dune_client.client import DuneClient
from dune_client.query import QueryBase
# setup Dune Python client
dune = DuneClient()
# define the query to run
query = QueryBase(
name="Sample Query",
query_id=1215383,
params=[
QueryParameter.text_type(name="TextField", value="Word"),
QueryParameter.number_type(name="NumberField", value=3.1415926535),
QueryParameter.date_type(name="DateField", value="2022-05-04 00:00:00"),
QueryParameter.enum_type(name="ListField", value="Option 1"),
],
)
result = dune.execute_query(query = query # pass in the query we just defined
, performance = "large" # define engine query is run on, default is "medium"
)
import requests
url = "https://api.dune.com/api/v1/query/{query_id}/execute"
headers = {"X-DUNE-API-KEY": "<x-dune-api-key>"}
response = requests.request("POST", url, headers=headers)
print(response.text)
const options = {method: 'POST', headers: {'X-DUNE-API-KEY': '<x-dune-api-key>'}};
fetch('https://api.dune.com/api/v1/query/{query_id}/execute', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.dune.com/api/v1/query/{query_id}/execute"
req, _ := http.NewRequest("POST", 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
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.dune.com/api/v1/query/{query_id}/execute",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
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;
}
HttpResponse<String> response = Unirest.post("https://api.dune.com/api/v1/query/{query_id}/execute")
.header("X-DUNE-API-KEY", "<x-dune-api-key>")
.asString();
{
"execution_id": "01HKZJ2683PHF9Q9PHHQ8FW4Q1",
"state": "QUERY_STATE_PENDING"
}{
"error": "Bad Request"
}{
"error": "Invalid API Key"
}{
"error": "This API request would exceed your configured limits per billing cycle."
}{
"error": "Not allowed to execute query. Query is archived, unsaved or not enough permissions"
}{
"error": "Object not found"
}{
"error": "Internal error"
}Execute Query
Execute, or run a query for the specified query ID
curl -X POST "https://api.dune.com/api/v1/query/{{query_id}}/execute" \
-H "X-Dune-API-Key: {{api_key}}" \
-H "Content-Type: application/json" \
-d '{"query_parameters": {"param1":24}, "performance": "large"}'
'''
Download Dune Python SDK by running `pip install dune-client`
For more info, visit the GitHub repository: https://github.com/duneanalytics/dune-client/tree/d2195b2a9577e2dcae5d2600cb3eddce20987f38
'''
import json
from dune_client.types import QueryParameter
from dune_client.client import DuneClient
from dune_client.query import QueryBase
# setup Dune Python client
dune = DuneClient()
# define the query to run
query = QueryBase(
name="Sample Query",
query_id=1215383,
params=[
QueryParameter.text_type(name="TextField", value="Word"),
QueryParameter.number_type(name="NumberField", value=3.1415926535),
QueryParameter.date_type(name="DateField", value="2022-05-04 00:00:00"),
QueryParameter.enum_type(name="ListField", value="Option 1"),
],
)
result = dune.execute_query(query = query # pass in the query we just defined
, performance = "large" # define engine query is run on, default is "medium"
)
import requests
url = "https://api.dune.com/api/v1/query/{query_id}/execute"
headers = {"X-DUNE-API-KEY": "<x-dune-api-key>"}
response = requests.request("POST", url, headers=headers)
print(response.text)
const options = {method: 'POST', headers: {'X-DUNE-API-KEY': '<x-dune-api-key>'}};
fetch('https://api.dune.com/api/v1/query/{query_id}/execute', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.dune.com/api/v1/query/{query_id}/execute"
req, _ := http.NewRequest("POST", 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
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.dune.com/api/v1/query/{query_id}/execute",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
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;
}
HttpResponse<String> response = Unirest.post("https://api.dune.com/api/v1/query/{query_id}/execute")
.header("X-DUNE-API-KEY", "<x-dune-api-key>")
.asString();
{
"execution_id": "01HKZJ2683PHF9Q9PHHQ8FW4Q1",
"state": "QUERY_STATE_PENDING"
}{
"error": "Bad Request"
}{
"error": "Invalid API Key"
}{
"error": "This API request would exceed your configured limits per billing cycle."
}{
"error": "Not allowed to execute query. Query is archived, unsaved or not enough permissions"
}{
"error": "Object not found"
}{
"error": "Internal error"
}ReadExecute query and get result in one call
Execute query and get result in one call
run_query to get result in JSON,
run_query_csv to get result in CSV format,
and run_query_dataframe to get result in Pandas dataframe
import json
from dune_client.types import QueryParameter
from dune_client.client import DuneClient
from dune_client.query import QueryBase
# setup Dune Python client
dune = DuneClient()
query = QueryBase(
name="Sample Query",
query_id=1215383,
)
result = dune.run_query(
query = query,
performance = 'large' # optionally define which tier to run the execution on (default is "medium")
)
# go over the results returned
for row in result.result.rows:
print (row) # as an example we print the rows
performance parameter, by default it will use the “medium” performance tier. Credits are consumed based on actual compute resources used. “large” tier provides more resources for complex queries.
Returns an execution_id associated with the triggered query execution and the state of the execution.
curl -X POST "https://api.dune.com/api/v1/query/{{query_id}}/execute" \
-H "X-Dune-API-Key: {{api_key}}" \
-H "Content-Type: application/json" \
-d '{"query_parameters": {"param1":24}, "performance": "large"}'
'''
Download Dune Python SDK by running `pip install dune-client`
For more info, visit the GitHub repository: https://github.com/duneanalytics/dune-client/tree/d2195b2a9577e2dcae5d2600cb3eddce20987f38
'''
import json
from dune_client.types import QueryParameter
from dune_client.client import DuneClient
from dune_client.query import QueryBase
# setup Dune Python client
dune = DuneClient()
# define the query to run
query = QueryBase(
name="Sample Query",
query_id=1215383,
params=[
QueryParameter.text_type(name="TextField", value="Word"),
QueryParameter.number_type(name="NumberField", value=3.1415926535),
QueryParameter.date_type(name="DateField", value="2022-05-04 00:00:00"),
QueryParameter.enum_type(name="ListField", value="Option 1"),
],
)
result = dune.execute_query(query = query # pass in the query we just defined
, performance = "large" # define engine query is run on, default is "medium"
)
import requests
url = "https://api.dune.com/api/v1/query/{query_id}/execute"
headers = {"X-DUNE-API-KEY": "<x-dune-api-key>"}
response = requests.request("POST", url, headers=headers)
print(response.text)
const options = {method: 'POST', headers: {'X-DUNE-API-KEY': '<x-dune-api-key>'}};
fetch('https://api.dune.com/api/v1/query/{query_id}/execute', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.dune.com/api/v1/query/{query_id}/execute"
req, _ := http.NewRequest("POST", 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
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.dune.com/api/v1/query/{query_id}/execute",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
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;
}
HttpResponse<String> response = Unirest.post("https://api.dune.com/api/v1/query/{query_id}/execute")
.header("X-DUNE-API-KEY", "<x-dune-api-key>")
.asString();
Headers
API Key for the service
Path Parameters
Unique identifier of the query
Query Parameters
Alternative to using the X-Dune-Api-Key header
The performance engine tier the execution will be run on. Can be small, medium, or large. Omit to use the default tier for the query engine. Credits are consumed based on actual compute resources used.
small, medium, large SQL Query parameters in json key-value pairs. Each parameter is to be provided in key-value pairs. This enables you to execute a parameterized query with the provided values for your parameter keys. Partial submission of parameters is allowed. For example, if the query expects three parameters and you only pass in two, the third one will automatically use its default value as defined in the Query Parameter Editor page.
Was this page helpful?