Tasks API
Trigger
Trigger a task by its identifier.
POST
/
api
/
v1
/
tasks
/
{taskIdentifier}
/
trigger
TypeScript
import { task } from "@trigger.dev/sdk";
export const myTask = await task({
id: "my-task",
run: async (payload: { message: string }) => {
console.log("Hello, world!");
}
});
// Somewhere else in your code
await myTask.trigger({ message: "Hello, world!" }, {
idempotencyKey: "unique-key-123",
concurrencyKey: "user123-task",
queue: {
name: "my-task-queue",
concurrencyLimit: 5
},
});curl -X POST "https://api.trigger.dev/api/v1/tasks/my-task/trigger" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tr_dev_1234" \
-d '{
"payload": {
"message": "Hello, world!"
},
"context": {
"user": "user123"
},
"options": {
"queue": {
"name": "default",
"concurrencyLimit": 5
},
"concurrencyKey": "user123-task",
"idempotencyKey": "unique-key-123"
}
}'import requests
url = "https://api.trigger.dev/api/v1/tasks/my-task/trigger"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer tr_dev_1234"
}
data = {
"payload": {
"message": "Hello, world!"
},
"context": {
"user": "user123"
},
"options": {
"queue": {
"name": "default",
"concurrencyLimit": 5
},
"concurrencyKey": "user123-task",
"idempotencyKey": "unique-key-123"
}
}
response = requests.post(url, headers=headers, json=data)
print(response.json())const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
payload: '<unknown>',
context: '<unknown>',
options: {
queue: {name: '<string>', concurrencyLimit: 500},
concurrencyKey: '<string>',
idempotencyKey: '<string>',
ttl: '1h42m',
delay: '<string>',
tags: 'user_123456',
machine: 'small-2x'
}
})
};
fetch('https://api.trigger.dev/api/v1/tasks/{taskIdentifier}/trigger', 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/tasks/{taskIdentifier}/trigger",
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([
'payload' => '<unknown>',
'context' => '<unknown>',
'options' => [
'queue' => [
'name' => '<string>',
'concurrencyLimit' => 500
],
'concurrencyKey' => '<string>',
'idempotencyKey' => '<string>',
'ttl' => '1h42m',
'delay' => '<string>',
'tags' => 'user_123456',
'machine' => 'small-2x'
]
]),
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/tasks/{taskIdentifier}/trigger"
payload := strings.NewReader("{\n \"payload\": \"<unknown>\",\n \"context\": \"<unknown>\",\n \"options\": {\n \"queue\": {\n \"name\": \"<string>\",\n \"concurrencyLimit\": 500\n },\n \"concurrencyKey\": \"<string>\",\n \"idempotencyKey\": \"<string>\",\n \"ttl\": \"1h42m\",\n \"delay\": \"<string>\",\n \"tags\": \"user_123456\",\n \"machine\": \"small-2x\"\n }\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/tasks/{taskIdentifier}/trigger")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"payload\": \"<unknown>\",\n \"context\": \"<unknown>\",\n \"options\": {\n \"queue\": {\n \"name\": \"<string>\",\n \"concurrencyLimit\": 500\n },\n \"concurrencyKey\": \"<string>\",\n \"idempotencyKey\": \"<string>\",\n \"ttl\": \"1h42m\",\n \"delay\": \"<string>\",\n \"tags\": \"user_123456\",\n \"machine\": \"small-2x\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trigger.dev/api/v1/tasks/{taskIdentifier}/trigger")
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 \"payload\": \"<unknown>\",\n \"context\": \"<unknown>\",\n \"options\": {\n \"queue\": {\n \"name\": \"<string>\",\n \"concurrencyLimit\": 500\n },\n \"concurrencyKey\": \"<string>\",\n \"idempotencyKey\": \"<string>\",\n \"ttl\": \"1h42m\",\n \"delay\": \"<string>\",\n \"tags\": \"user_123456\",\n \"machine\": \"small-2x\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "run_1234"
}{
"error": "Something went wrong"
}{
"error": "Something went wrong"
}{
"error": "Something went wrong"
}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 a task
Body
application/json
Response
Task triggered successfully
The ID of the run that was triggered.
Example:
"run_1234"
Was this page helpful?
Previous
Batch triggerBatch trigger tasks with up to 1,000 payloads with SDK 4.3.1+ (500 in prior versions).
Next
⌘I
TypeScript
import { task } from "@trigger.dev/sdk";
export const myTask = await task({
id: "my-task",
run: async (payload: { message: string }) => {
console.log("Hello, world!");
}
});
// Somewhere else in your code
await myTask.trigger({ message: "Hello, world!" }, {
idempotencyKey: "unique-key-123",
concurrencyKey: "user123-task",
queue: {
name: "my-task-queue",
concurrencyLimit: 5
},
});curl -X POST "https://api.trigger.dev/api/v1/tasks/my-task/trigger" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tr_dev_1234" \
-d '{
"payload": {
"message": "Hello, world!"
},
"context": {
"user": "user123"
},
"options": {
"queue": {
"name": "default",
"concurrencyLimit": 5
},
"concurrencyKey": "user123-task",
"idempotencyKey": "unique-key-123"
}
}'import requests
url = "https://api.trigger.dev/api/v1/tasks/my-task/trigger"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer tr_dev_1234"
}
data = {
"payload": {
"message": "Hello, world!"
},
"context": {
"user": "user123"
},
"options": {
"queue": {
"name": "default",
"concurrencyLimit": 5
},
"concurrencyKey": "user123-task",
"idempotencyKey": "unique-key-123"
}
}
response = requests.post(url, headers=headers, json=data)
print(response.json())const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
payload: '<unknown>',
context: '<unknown>',
options: {
queue: {name: '<string>', concurrencyLimit: 500},
concurrencyKey: '<string>',
idempotencyKey: '<string>',
ttl: '1h42m',
delay: '<string>',
tags: 'user_123456',
machine: 'small-2x'
}
})
};
fetch('https://api.trigger.dev/api/v1/tasks/{taskIdentifier}/trigger', 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/tasks/{taskIdentifier}/trigger",
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([
'payload' => '<unknown>',
'context' => '<unknown>',
'options' => [
'queue' => [
'name' => '<string>',
'concurrencyLimit' => 500
],
'concurrencyKey' => '<string>',
'idempotencyKey' => '<string>',
'ttl' => '1h42m',
'delay' => '<string>',
'tags' => 'user_123456',
'machine' => 'small-2x'
]
]),
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/tasks/{taskIdentifier}/trigger"
payload := strings.NewReader("{\n \"payload\": \"<unknown>\",\n \"context\": \"<unknown>\",\n \"options\": {\n \"queue\": {\n \"name\": \"<string>\",\n \"concurrencyLimit\": 500\n },\n \"concurrencyKey\": \"<string>\",\n \"idempotencyKey\": \"<string>\",\n \"ttl\": \"1h42m\",\n \"delay\": \"<string>\",\n \"tags\": \"user_123456\",\n \"machine\": \"small-2x\"\n }\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/tasks/{taskIdentifier}/trigger")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"payload\": \"<unknown>\",\n \"context\": \"<unknown>\",\n \"options\": {\n \"queue\": {\n \"name\": \"<string>\",\n \"concurrencyLimit\": 500\n },\n \"concurrencyKey\": \"<string>\",\n \"idempotencyKey\": \"<string>\",\n \"ttl\": \"1h42m\",\n \"delay\": \"<string>\",\n \"tags\": \"user_123456\",\n \"machine\": \"small-2x\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trigger.dev/api/v1/tasks/{taskIdentifier}/trigger")
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 \"payload\": \"<unknown>\",\n \"context\": \"<unknown>\",\n \"options\": {\n \"queue\": {\n \"name\": \"<string>\",\n \"concurrencyLimit\": 500\n },\n \"concurrencyKey\": \"<string>\",\n \"idempotencyKey\": \"<string>\",\n \"ttl\": \"1h42m\",\n \"delay\": \"<string>\",\n \"tags\": \"user_123456\",\n \"machine\": \"small-2x\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "run_1234"
}{
"error": "Something went wrong"
}{
"error": "Something went wrong"
}{
"error": "Something went wrong"
}
