Add dashboard widget
Add a widget to a custom dashboard. Without a position it is placed full width at the bottom.
import { query } from "@trigger.dev/sdk";
const { widgetId } = await query.dashboards.widgets.add("dashboard_1234", {
title: "Failed runs",
query: "SELECT count() AS failed FROM runs WHERE status = 'Failed'",
display: { type: "bignumber", column: "failed", aggregation: "sum" },
});curl --request POST \
--url https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}/widgets \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"title": "<string>",
"display": {
"type": "table",
"prettyFormatting": true,
"sorting": [
{
"id": "<string>",
"desc": true
}
]
},
"id": "<string>",
"query": "<string>",
"fillGaps": true,
"revision": "<string>"
}
'import requests
url = "https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}/widgets"
payload = {
"title": "<string>",
"display": {
"type": "table",
"prettyFormatting": True,
"sorting": [
{
"id": "<string>",
"desc": True
}
]
},
"id": "<string>",
"query": "<string>",
"fillGaps": True,
"revision": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
title: '<string>',
display: {type: 'table', prettyFormatting: true, sorting: [{id: '<string>', desc: true}]},
id: '<string>',
query: '<string>',
fillGaps: true,
revision: '<string>'
})
};
fetch('https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}/widgets', 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}/widgets",
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([
'title' => '<string>',
'display' => [
'type' => 'table',
'prettyFormatting' => true,
'sorting' => [
[
'id' => '<string>',
'desc' => true
]
]
],
'id' => '<string>',
'query' => '<string>',
'fillGaps' => true,
'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}/widgets"
payload := strings.NewReader("{\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 \"revision\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", 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.post("https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}/widgets")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\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 \"revision\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}/widgets")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\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 \"revision\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"widgetId": "<string>",
"dashboard": {
"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
200How the widget renders its query results.
- Table
- Chart
- Big number
- Section title
Show child attributes
Show child attributes
Omit to generate one. Letters, numbers, _ and -, unique within the dashboard.
A TRQL query. Required unless the display type is title.
Fill empty time buckets, carrying gauges forward and zero-filling counters.
A position on the dashboard's 12-column grid.
Show child attributes
Show child attributes
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.
Was this page helpful?
import { query } from "@trigger.dev/sdk";
const { widgetId } = await query.dashboards.widgets.add("dashboard_1234", {
title: "Failed runs",
query: "SELECT count() AS failed FROM runs WHERE status = 'Failed'",
display: { type: "bignumber", column: "failed", aggregation: "sum" },
});curl --request POST \
--url https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}/widgets \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"title": "<string>",
"display": {
"type": "table",
"prettyFormatting": true,
"sorting": [
{
"id": "<string>",
"desc": true
}
]
},
"id": "<string>",
"query": "<string>",
"fillGaps": true,
"revision": "<string>"
}
'import requests
url = "https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}/widgets"
payload = {
"title": "<string>",
"display": {
"type": "table",
"prettyFormatting": True,
"sorting": [
{
"id": "<string>",
"desc": True
}
]
},
"id": "<string>",
"query": "<string>",
"fillGaps": True,
"revision": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
title: '<string>',
display: {type: 'table', prettyFormatting: true, sorting: [{id: '<string>', desc: true}]},
id: '<string>',
query: '<string>',
fillGaps: true,
revision: '<string>'
})
};
fetch('https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}/widgets', 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}/widgets",
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([
'title' => '<string>',
'display' => [
'type' => 'table',
'prettyFormatting' => true,
'sorting' => [
[
'id' => '<string>',
'desc' => true
]
]
],
'id' => '<string>',
'query' => '<string>',
'fillGaps' => true,
'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}/widgets"
payload := strings.NewReader("{\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 \"revision\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", 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.post("https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}/widgets")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\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 \"revision\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trigger.dev/api/v1/query/dashboards/{dashboardId}/widgets")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\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 \"revision\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"widgetId": "<string>",
"dashboard": {
"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
}
}
]
}
}
