Replace dashboard widgets
Replace every widget on a custom dashboard, and optionally its title and description. A widget that already exists keeps its position unless you pass a new one; new widgets without a position are stacked full width below the others, in order.
import { query } from "@trigger.dev/sdk";
const current = await query.dashboards.retrieve("dashboard_1234");
await query.dashboards.replace("dashboard_1234", {
widgets: [
{
title: "Runs by status",
query: "SELECT status, count() AS runs FROM runs GROUP BY status",
display: { type: "table" },
},
],
revision: current.revision,
});curl --request PUT \
--url https://api.trigger.dev/api/v1/query/dashboards/{dashboardId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"widgets": [
{
"title": "<string>",
"display": {
"type": "table",
"prettyFormatting": true,
"sorting": [
{
"id": "<string>",
"desc": true
}
]
},
"id": "<string>",
"query": "<string>",
"fillGaps": true
}
],
"title": "<string>",
"description": "<string>",
"revision": "<string>"
}
'import requests
url = "https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}"
payload = {
"widgets": [
{
"title": "<string>",
"display": {
"type": "table",
"prettyFormatting": True,
"sorting": [
{
"id": "<string>",
"desc": True
}
]
},
"id": "<string>",
"query": "<string>",
"fillGaps": True
}
],
"title": "<string>",
"description": "<string>",
"revision": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
widgets: [
{
title: '<string>',
display: {type: 'table', prettyFormatting: true, sorting: [{id: '<string>', desc: true}]},
id: '<string>',
query: '<string>',
fillGaps: true
}
],
title: '<string>',
description: '<string>',
revision: '<string>'
})
};
fetch('https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}', 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.trigger.dev/api/v1/query/dashboards/{dashboardId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'widgets' => [
[
'title' => '<string>',
'display' => [
'type' => 'table',
'prettyFormatting' => true,
'sorting' => [
[
'id' => '<string>',
'desc' => true
]
]
],
'id' => '<string>',
'query' => '<string>',
'fillGaps' => true
]
],
'title' => '<string>',
'description' => '<string>',
'revision' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.trigger.dev/api/v1/query/dashboards/{dashboardId}"
payload := strings.NewReader("{\n \"widgets\": [\n {\n \"title\": \"<string>\",\n \"display\": {\n \"type\": \"table\",\n \"prettyFormatting\": true,\n \"sorting\": [\n {\n \"id\": \"<string>\",\n \"desc\": true\n }\n ]\n },\n \"id\": \"<string>\",\n \"query\": \"<string>\",\n \"fillGaps\": true\n }\n ],\n \"title\": \"<string>\",\n \"description\": \"<string>\",\n \"revision\": \"<string>\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"widgets\": [\n {\n \"title\": \"<string>\",\n \"display\": {\n \"type\": \"table\",\n \"prettyFormatting\": true,\n \"sorting\": [\n {\n \"id\": \"<string>\",\n \"desc\": true\n }\n ]\n },\n \"id\": \"<string>\",\n \"query\": \"<string>\",\n \"fillGaps\": true\n }\n ],\n \"title\": \"<string>\",\n \"description\": \"<string>\",\n \"revision\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"widgets\": [\n {\n \"title\": \"<string>\",\n \"display\": {\n \"type\": \"table\",\n \"prettyFormatting\": true,\n \"sorting\": [\n {\n \"id\": \"<string>\",\n \"desc\": true\n }\n ]\n },\n \"id\": \"<string>\",\n \"query\": \"<string>\",\n \"fillGaps\": true\n }\n ],\n \"title\": \"<string>\",\n \"description\": \"<string>\",\n \"revision\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"title": "<string>",
"description": "<string>",
"revision": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z",
"widgets": [
{
"id": "<string>",
"title": "<string>",
"query": "<string>",
"display": {
"type": "table",
"prettyFormatting": true,
"sorting": [
{
"id": "<string>",
"desc": true
}
]
},
"fillGaps": true,
"position": {
"x": 5,
"y": 1,
"w": 6,
"h": 2
}
}
]
}Authorizations
Use a named environment API key. It starts with tr_dev_sk_, tr_prod_sk_, tr_stg_sk_, etc.
Create a named API key in the API Keys section of your Trigger.dev project dashboard. Choose the narrowest access preset that supports your integration.
Our TypeScript SDK will default to using the value of the TRIGGER_SECRET_KEY environment variable if it is set. If you are using the SDK in a different environment, you can set the key using the configure function.
import { configure } from "@trigger.dev/sdk"; configure({ accessToken: "tr_dev_sk_1234" });
Path Parameters
The custom dashboard id, starting with dashboard_
Body
Response
The updated dashboard
The dashboard id, starting with dashboard_
The revision from the dashboard you last read. Send it to reject the write with a 409 if someone else changed the dashboard in the meantime.
Widgets in grid order, top to bottom then left to right.
Show child attributes
Show child attributes
Was this page helpful?
import { query } from "@trigger.dev/sdk";
const current = await query.dashboards.retrieve("dashboard_1234");
await query.dashboards.replace("dashboard_1234", {
widgets: [
{
title: "Runs by status",
query: "SELECT status, count() AS runs FROM runs GROUP BY status",
display: { type: "table" },
},
],
revision: current.revision,
});curl --request PUT \
--url https://api.trigger.dev/api/v1/query/dashboards/{dashboardId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"widgets": [
{
"title": "<string>",
"display": {
"type": "table",
"prettyFormatting": true,
"sorting": [
{
"id": "<string>",
"desc": true
}
]
},
"id": "<string>",
"query": "<string>",
"fillGaps": true
}
],
"title": "<string>",
"description": "<string>",
"revision": "<string>"
}
'import requests
url = "https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}"
payload = {
"widgets": [
{
"title": "<string>",
"display": {
"type": "table",
"prettyFormatting": True,
"sorting": [
{
"id": "<string>",
"desc": True
}
]
},
"id": "<string>",
"query": "<string>",
"fillGaps": True
}
],
"title": "<string>",
"description": "<string>",
"revision": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
widgets: [
{
title: '<string>',
display: {type: 'table', prettyFormatting: true, sorting: [{id: '<string>', desc: true}]},
id: '<string>',
query: '<string>',
fillGaps: true
}
],
title: '<string>',
description: '<string>',
revision: '<string>'
})
};
fetch('https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}', 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.trigger.dev/api/v1/query/dashboards/{dashboardId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'widgets' => [
[
'title' => '<string>',
'display' => [
'type' => 'table',
'prettyFormatting' => true,
'sorting' => [
[
'id' => '<string>',
'desc' => true
]
]
],
'id' => '<string>',
'query' => '<string>',
'fillGaps' => true
]
],
'title' => '<string>',
'description' => '<string>',
'revision' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.trigger.dev/api/v1/query/dashboards/{dashboardId}"
payload := strings.NewReader("{\n \"widgets\": [\n {\n \"title\": \"<string>\",\n \"display\": {\n \"type\": \"table\",\n \"prettyFormatting\": true,\n \"sorting\": [\n {\n \"id\": \"<string>\",\n \"desc\": true\n }\n ]\n },\n \"id\": \"<string>\",\n \"query\": \"<string>\",\n \"fillGaps\": true\n }\n ],\n \"title\": \"<string>\",\n \"description\": \"<string>\",\n \"revision\": \"<string>\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"widgets\": [\n {\n \"title\": \"<string>\",\n \"display\": {\n \"type\": \"table\",\n \"prettyFormatting\": true,\n \"sorting\": [\n {\n \"id\": \"<string>\",\n \"desc\": true\n }\n ]\n },\n \"id\": \"<string>\",\n \"query\": \"<string>\",\n \"fillGaps\": true\n }\n ],\n \"title\": \"<string>\",\n \"description\": \"<string>\",\n \"revision\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"widgets\": [\n {\n \"title\": \"<string>\",\n \"display\": {\n \"type\": \"table\",\n \"prettyFormatting\": true,\n \"sorting\": [\n {\n \"id\": \"<string>\",\n \"desc\": true\n }\n ]\n },\n \"id\": \"<string>\",\n \"query\": \"<string>\",\n \"fillGaps\": true\n }\n ],\n \"title\": \"<string>\",\n \"description\": \"<string>\",\n \"revision\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"title": "<string>",
"description": "<string>",
"revision": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z",
"widgets": [
{
"id": "<string>",
"title": "<string>",
"query": "<string>",
"display": {
"type": "table",
"prettyFormatting": true,
"sorting": [
{
"id": "<string>",
"desc": true
}
]
},
"fillGaps": true,
"position": {
"x": 5,
"y": 1,
"w": 6,
"h": 2
}
}
]
}
