Tasks API
Batch trigger
Batch trigger tasks with up to 1,000 payloads with SDK 4.3.1+ (500 in prior versions).
POST
/
api
/
v1
/
tasks
/
batch
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.batchTrigger([
{
payload: { message: "Hello, world!" },
options: {
idempotencyKey: "unique-key-123",
concurrencyKey: "user-123-task",
queue: {
name: "my-task-queue",
concurrencyLimit: 5
}
}
}
]);curl -X POST "https://api.trigger.dev/api/v1/tasks/batch" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tr_dev_sk_1234" \
-d '{
"items": [
{
"task": "my-task",
"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/batch"
payload = { "items": [
{
"task": "<string>",
"payload": "<unknown>",
"context": "<unknown>",
"options": {
"queue": {
"name": "<string>",
"concurrencyLimit": 500
},
"concurrencyKey": "<string>",
"idempotencyKey": "<string>",
"ttl": "1h42m",
"delay": "<string>",
"tags": "user_123456",
"machine": "small-2x"
}
}
] }
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({
items: [
{
task: '<string>',
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/batch', 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/batch",
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([
'items' => [
[
'task' => '<string>',
'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/batch"
payload := strings.NewReader("{\n \"items\": [\n {\n \"task\": \"<string>\",\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 }\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/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"items\": [\n {\n \"task\": \"<string>\",\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 }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trigger.dev/api/v1/tasks/batch")
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 \"items\": [\n {\n \"task\": \"<string>\",\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 }\n ]\n}"
response = http.request(request)
puts response.read_body{
"batchId": "batch_1234",
"runs": [
"<string>"
]
}{
"error": "Something went wrong"
}{
"error": "Something went wrong"
}{
"error": "Something went wrong"
}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" });
Body
application/json
An array of payloads to trigger the task with
Show child attributes
Show child attributes
Was this page helpful?
⌘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.batchTrigger([
{
payload: { message: "Hello, world!" },
options: {
idempotencyKey: "unique-key-123",
concurrencyKey: "user-123-task",
queue: {
name: "my-task-queue",
concurrencyLimit: 5
}
}
}
]);curl -X POST "https://api.trigger.dev/api/v1/tasks/batch" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tr_dev_sk_1234" \
-d '{
"items": [
{
"task": "my-task",
"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/batch"
payload = { "items": [
{
"task": "<string>",
"payload": "<unknown>",
"context": "<unknown>",
"options": {
"queue": {
"name": "<string>",
"concurrencyLimit": 500
},
"concurrencyKey": "<string>",
"idempotencyKey": "<string>",
"ttl": "1h42m",
"delay": "<string>",
"tags": "user_123456",
"machine": "small-2x"
}
}
] }
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({
items: [
{
task: '<string>',
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/batch', 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/batch",
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([
'items' => [
[
'task' => '<string>',
'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/batch"
payload := strings.NewReader("{\n \"items\": [\n {\n \"task\": \"<string>\",\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 }\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/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"items\": [\n {\n \"task\": \"<string>\",\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 }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trigger.dev/api/v1/tasks/batch")
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 \"items\": [\n {\n \"task\": \"<string>\",\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 }\n ]\n}"
response = http.request(request)
puts response.read_body{
"batchId": "batch_1234",
"runs": [
"<string>"
]
}{
"error": "Something went wrong"
}{
"error": "Something went wrong"
}{
"error": "Something went wrong"
}
