Runs API
Update metadata
Update the metadata of a run.
PUT
/
api
/
v1
/
runs
/
{runId}
/
metadata
Save metadata
import { metadata, task } from "@trigger.dev/sdk";
export const myTask = task({
id: "my-task",
run: async () => {
await metadata.save({ key: "value" });
}
});curl --request PUT \
--url https://api.trigger.dev/api/v1/runs/{runId}/metadata \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"metadata": {
"key": "value"
}
}
'import requests
url = "https://api.trigger.dev/api/v1/runs/{runId}/metadata"
payload = { "metadata": { "key": "value" } }
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({metadata: {key: 'value'}})
};
fetch('https://api.trigger.dev/api/v1/runs/{runId}/metadata', 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/runs/{runId}/metadata",
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([
'metadata' => [
'key' => 'value'
]
]),
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/runs/{runId}/metadata"
payload := strings.NewReader("{\n \"metadata\": {\n \"key\": \"value\"\n }\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/runs/{runId}/metadata")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"metadata\": {\n \"key\": \"value\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trigger.dev/api/v1/runs/{runId}/metadata")
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 \"metadata\": {\n \"key\": \"value\"\n }\n}"
response = http.request(request)
puts response.read_body{
"metadata": {}
}{}{
"error": "Invalid or Missing API key"
}{
"error": "Task Run not found"
}Authorizations
Use your project-specific Secret API key. Will start with tr_dev_, tr_prod, tr_stg, etc.
You can find your Secret API key in the API Keys section of your Trigger.dev project dashboard.
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_1234" });
Path Parameters
The ID of an run, starts with run_. The run ID will be returned when you trigger a run on a task.
Body
application/json
The new metadata to set on the run.
Example:
{ "key": "value" }
Response
Successful request
The updated metadata of the run.
Was this page helpful?
Previous
Add tags to a runAdds one or more tags to a run. Runs can have a maximum of 10 tags. Duplicate tags are ignored.
Next
⌘I
Save metadata
import { metadata, task } from "@trigger.dev/sdk";
export const myTask = task({
id: "my-task",
run: async () => {
await metadata.save({ key: "value" });
}
});curl --request PUT \
--url https://api.trigger.dev/api/v1/runs/{runId}/metadata \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"metadata": {
"key": "value"
}
}
'import requests
url = "https://api.trigger.dev/api/v1/runs/{runId}/metadata"
payload = { "metadata": { "key": "value" } }
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({metadata: {key: 'value'}})
};
fetch('https://api.trigger.dev/api/v1/runs/{runId}/metadata', 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/runs/{runId}/metadata",
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([
'metadata' => [
'key' => 'value'
]
]),
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/runs/{runId}/metadata"
payload := strings.NewReader("{\n \"metadata\": {\n \"key\": \"value\"\n }\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/runs/{runId}/metadata")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"metadata\": {\n \"key\": \"value\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trigger.dev/api/v1/runs/{runId}/metadata")
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 \"metadata\": {\n \"key\": \"value\"\n }\n}"
response = http.request(request)
puts response.read_body{
"metadata": {}
}{}{
"error": "Invalid or Missing API key"
}{
"error": "Task Run not found"
}
