Tasks API
Trigger task batch
Batch trigger a specific task with up to 1,000 payloads. All items in the batch run the same task.
POST
/
api
/
v1
/
tasks
/
{taskIdentifier}
/
batch
TypeScript
import { task } from "@trigger.dev/sdk";
export const myTask = 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!" } },
{ payload: { message: "Hello again!" } },
]);curl -X POST "https://api.trigger.dev/api/v1/tasks/my-task/batch" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tr_dev_1234" \
-d '{
"items": [
{ "payload": { "message": "Hello, world!" } },
{ "payload": { "message": "Hello again!" } }
]
}'import requests
url = "https://api.trigger.dev/api/v1/tasks/{taskIdentifier}/batch"
payload = { "items": [
{
"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: [
{
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}/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/{taskIdentifier}/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' => [
[
'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}/batch"
payload := strings.NewReader("{\n \"items\": [\n {\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/{taskIdentifier}/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"items\": [\n {\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/{taskIdentifier}/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 \"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 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
An array of payloads to trigger the task with (max 1,000 items).
Maximum array length:
1000Show child attributes
Show child attributes
Was this page helpful?
Previous
Create batchPhase 1 of 2-phase batch API. Creates a batch record and optionally blocks the parent run for batchTriggerAndWait.
After creating a batch, stream items via POST /api/v3/batches/{batchId}/items.
Next
⌘I
TypeScript
import { task } from "@trigger.dev/sdk";
export const myTask = 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!" } },
{ payload: { message: "Hello again!" } },
]);curl -X POST "https://api.trigger.dev/api/v1/tasks/my-task/batch" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer tr_dev_1234" \
-d '{
"items": [
{ "payload": { "message": "Hello, world!" } },
{ "payload": { "message": "Hello again!" } }
]
}'import requests
url = "https://api.trigger.dev/api/v1/tasks/{taskIdentifier}/batch"
payload = { "items": [
{
"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: [
{
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}/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/{taskIdentifier}/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' => [
[
'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}/batch"
payload := strings.NewReader("{\n \"items\": [\n {\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/{taskIdentifier}/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"items\": [\n {\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/{taskIdentifier}/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 \"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"
}
