This upserts (create or replace) a materialized view from an existing query
curl --request POST \
--url https://api.dune.com/api/v1/materialized-views \
--header 'Content-Type: */*' \
--header 'X-Dune-Api-Key: <x-dune-api-key>' \
--data '
{
"cron_expression": "<string>",
"expires_at": "<string>",
"is_private": true,
"name": "<string>",
"performance": "<string>",
"query_id": 123
}
'import requests
url = "https://api.dune.com/api/v1/materialized-views"
payload = {
"cron_expression": "<string>",
"expires_at": "<string>",
"is_private": True,
"name": "<string>",
"performance": "<string>",
"query_id": 123
}
headers = {
"X-Dune-Api-Key": "<x-dune-api-key>",
"Content-Type": "*/*"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Dune-Api-Key': '<x-dune-api-key>', 'Content-Type': '*/*'},
body: JSON.stringify({
cron_expression: '<string>',
expires_at: '<string>',
is_private: true,
name: '<string>',
performance: '<string>',
query_id: 123
})
};
fetch('https://api.dune.com/api/v1/materialized-views', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.dune.com/api/v1/materialized-views",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'cron_expression' => '<string>',
'expires_at' => '<string>',
'is_private' => true,
'name' => '<string>',
'performance' => '<string>',
'query_id' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: */*",
"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;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.dune.com/api/v1/materialized-views"
payload := strings.NewReader("{\n \"cron_expression\": \"<string>\",\n \"expires_at\": \"<string>\",\n \"is_private\": true,\n \"name\": \"<string>\",\n \"performance\": \"<string>\",\n \"query_id\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Dune-Api-Key", "<x-dune-api-key>")
req.Header.Add("Content-Type", "*/*")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.dune.com/api/v1/materialized-views")
.header("X-Dune-Api-Key", "<x-dune-api-key>")
.header("Content-Type", "*/*")
.body("{\n \"cron_expression\": \"<string>\",\n \"expires_at\": \"<string>\",\n \"is_private\": true,\n \"name\": \"<string>\",\n \"performance\": \"<string>\",\n \"query_id\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.dune.com/api/v1/materialized-views")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Dune-Api-Key"] = '<x-dune-api-key>'
request["Content-Type"] = '*/*'
request.body = "{\n \"cron_expression\": \"<string>\",\n \"expires_at\": \"<string>\",\n \"is_private\": true,\n \"name\": \"<string>\",\n \"performance\": \"<string>\",\n \"query_id\": 123\n}"
response = http.request(request)
puts response.read_body{
"execution_id": "01HZ065JVE23C23FM2HKWQP2RT",
"name": "dune.dune.result_erc_20_token_summary"
}{
"error": "Bad Request"
}{
"error": "Invalid API Key"
}{
"error": "Object not found"
}{
"error": "Internal error"
}Materialized Views
Upsert Materialized View
This upserts a materialized view from an existing query. If the materialized view with the given name
POST
/
v1
/
materialized-views
This upserts (create or replace) a materialized view from an existing query
curl --request POST \
--url https://api.dune.com/api/v1/materialized-views \
--header 'Content-Type: */*' \
--header 'X-Dune-Api-Key: <x-dune-api-key>' \
--data '
{
"cron_expression": "<string>",
"expires_at": "<string>",
"is_private": true,
"name": "<string>",
"performance": "<string>",
"query_id": 123
}
'import requests
url = "https://api.dune.com/api/v1/materialized-views"
payload = {
"cron_expression": "<string>",
"expires_at": "<string>",
"is_private": True,
"name": "<string>",
"performance": "<string>",
"query_id": 123
}
headers = {
"X-Dune-Api-Key": "<x-dune-api-key>",
"Content-Type": "*/*"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Dune-Api-Key': '<x-dune-api-key>', 'Content-Type': '*/*'},
body: JSON.stringify({
cron_expression: '<string>',
expires_at: '<string>',
is_private: true,
name: '<string>',
performance: '<string>',
query_id: 123
})
};
fetch('https://api.dune.com/api/v1/materialized-views', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.dune.com/api/v1/materialized-views",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'cron_expression' => '<string>',
'expires_at' => '<string>',
'is_private' => true,
'name' => '<string>',
'performance' => '<string>',
'query_id' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: */*",
"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;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.dune.com/api/v1/materialized-views"
payload := strings.NewReader("{\n \"cron_expression\": \"<string>\",\n \"expires_at\": \"<string>\",\n \"is_private\": true,\n \"name\": \"<string>\",\n \"performance\": \"<string>\",\n \"query_id\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Dune-Api-Key", "<x-dune-api-key>")
req.Header.Add("Content-Type", "*/*")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.dune.com/api/v1/materialized-views")
.header("X-Dune-Api-Key", "<x-dune-api-key>")
.header("Content-Type", "*/*")
.body("{\n \"cron_expression\": \"<string>\",\n \"expires_at\": \"<string>\",\n \"is_private\": true,\n \"name\": \"<string>\",\n \"performance\": \"<string>\",\n \"query_id\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.dune.com/api/v1/materialized-views")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Dune-Api-Key"] = '<x-dune-api-key>'
request["Content-Type"] = '*/*'
request.body = "{\n \"cron_expression\": \"<string>\",\n \"expires_at\": \"<string>\",\n \"is_private\": true,\n \"name\": \"<string>\",\n \"performance\": \"<string>\",\n \"query_id\": 123\n}"
response = http.request(request)
puts response.read_body{
"execution_id": "01HZ065JVE23C23FM2HKWQP2RT",
"name": "dune.dune.result_erc_20_token_summary"
}{
"error": "Bad Request"
}{
"error": "Invalid API Key"
}{
"error": "Object not found"
}{
"error": "Internal error"
}Minimum required API key scope:
Read/Write- This endpoint will create a new matview if none exists for the given query ID, or update an existing one if the query ID matches.
- It will fail to create a matview with the same name as an existing one, but for a different query ID
- The name of the matview is just the last part of the matview, not including
dune.<your_team>.and must be prefixed withresult_ - The
cron_expressionparameter must be passed in as a valid 5 section cron expression. See here for how to write them.
- The cron expression interval must be at least 15 minutes and at most weekly
Headers
API Key for the service
Query Parameters
API Key, alternative to using the HTTP header X-Dune-Api-Key
Body
*/*
MatviewsUpsertRequest
Was this page helpful?