Create a batch of email messages
Creates up to 50 email messages in a single request.
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.emailMessages.batch({
messages: [],
});
console.log(response.data);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.email_messages.batch(
messages=[],
)
print(response.data)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.EmailMessages.Batch(
context.TODO(),
telnyx.EmailMessageBatchParams{
Messages: "messages",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Data)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.emailMessages.EmailMessageBatchParams;
import java.util.List;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
EmailMessageBatchParams params = EmailMessageBatchParams.builder()
.messages(List.of())
.build();
var response = client.emailMessages().batch(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.email_messages.batch(messages: [])
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->emailMessages->batch(
messages: [],
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx email-messages batch \
--api-key 'My API Key' \
--messages messagescurl --request POST \
--url https://api.telnyx.com/v2/email_messages/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"sandbox_mode": false,
"messages": [
{
"from": "sender@example.com",
"to": [
"recipient1@example.com"
],
"subject": "Hello 1",
"text_body": "Message 1"
},
{
"from": "sender@example.com",
"to": [
"recipient2@example.com"
],
"subject": "Hello 2",
"text_body": "Message 2"
}
]
}
'{
"data": [
{
"record_type": "email_message",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"from": {
"email": "<string>",
"name": "<string>"
},
"to": [
{
"email": "<string>",
"name": "<string>"
}
],
"cc": [
{
"email": "<string>",
"name": "<string>"
}
],
"bcc": [
{
"email": "<string>",
"name": "<string>"
}
],
"reply_to": "<string>",
"subject": "<string>",
"template_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"template_variables": {},
"attachments": [
{
"url": "<string>",
"sha256": "<string>",
"size_bytes": 123,
"filename": "<string>",
"content_type": "<string>",
"disposition": "attachment",
"content_id": "<string>"
}
],
"events": [
{
"occurred_at": "2023-11-07T05:31:56Z",
"payload": {}
}
],
"created_at": "2023-11-07T05:31:56Z",
"scheduled_at": "2023-11-07T05:31:56Z",
"inline_css": true,
"sandbox": true,
"recipient_statuses": {
"delivered": 998,
"bounced": 2
}
}
],
"errors": [
{
"index": 1,
"message": "<string>"
}
],
"meta": {
"total": 1,
"succeeded": 1,
"failed": 1
}
}{
"errors": [
{
"code": "10015",
"title": "Bad Request",
"detail": "email is required"
}
]
}{
"errors": [
{
"code": "10006",
"title": "Not authorized",
"detail": "Invalid API key",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10006"
}
}
]
}{
"errors": [
{
"code": "10036",
"title": "Resource is being processed",
"detail": "A request with this Idempotency-Key is already being processed.",
"source": {
"pointer": "/header/Idempotency-Key"
}
}
]
}{
"errors": [
{
"code": "10007",
"title": "Unexpected error",
"detail": "An unexpected error occured."
}
]
}{
"errors": [
{
"code": "10027",
"title": "Unprocessable Entity",
"detail": "The server understood the syntax of the request but was unable to process the instructions."
}
]
}{
"errors": [
{
"code": "reputation_suspended",
"title": "Sending Suspended",
"detail": "<string>"
}
]
}{
"errors": [
{
"code": "10016",
"title": "Service Unavailable",
"detail": "The email domain service is temporarily unavailable. Please try again later."
}
]
}Authorizations
Telnyx API key supplied as Authorization: Bearer <token>. In production, auth may be validated by the API gateway and forwarded via Telnyx auth headers.
Headers
Optional opaque, unquoted key for safely retrying the same logical request. Keys must contain 1 to 255 letters, numbers, hyphens, or underscores. Generate a unique UUID v4 for each operation and reuse it only when retrying that operation with the same request. Invalid headersโincluding duplicate, empty, malformed, or overlong valuesโreturn 400 with error code 10015. A request already in progress with the same key returns 409; reusing the key with a different request returns 422. Only successful responses are replayed, for up to 24 hours. Do not include sensitive data in the key.
1 - 255^[A-Za-z0-9_-]{1,255}$Body
Response
Multi-Status โ all batch responses return 207. When all messages succeed, errors is empty and every item is in data. When one or more fail, the response contains a data array for successes and an errors array for failures.
Was this page helpful?
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.emailMessages.batch({
messages: [],
});
console.log(response.data);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.email_messages.batch(
messages=[],
)
print(response.data)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.EmailMessages.Batch(
context.TODO(),
telnyx.EmailMessageBatchParams{
Messages: "messages",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Data)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.emailMessages.EmailMessageBatchParams;
import java.util.List;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
EmailMessageBatchParams params = EmailMessageBatchParams.builder()
.messages(List.of())
.build();
var response = client.emailMessages().batch(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.email_messages.batch(messages: [])
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->emailMessages->batch(
messages: [],
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx email-messages batch \
--api-key 'My API Key' \
--messages messagescurl --request POST \
--url https://api.telnyx.com/v2/email_messages/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"sandbox_mode": false,
"messages": [
{
"from": "sender@example.com",
"to": [
"recipient1@example.com"
],
"subject": "Hello 1",
"text_body": "Message 1"
},
{
"from": "sender@example.com",
"to": [
"recipient2@example.com"
],
"subject": "Hello 2",
"text_body": "Message 2"
}
]
}
'{
"data": [
{
"record_type": "email_message",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"from": {
"email": "<string>",
"name": "<string>"
},
"to": [
{
"email": "<string>",
"name": "<string>"
}
],
"cc": [
{
"email": "<string>",
"name": "<string>"
}
],
"bcc": [
{
"email": "<string>",
"name": "<string>"
}
],
"reply_to": "<string>",
"subject": "<string>",
"template_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"template_variables": {},
"attachments": [
{
"url": "<string>",
"sha256": "<string>",
"size_bytes": 123,
"filename": "<string>",
"content_type": "<string>",
"disposition": "attachment",
"content_id": "<string>"
}
],
"events": [
{
"occurred_at": "2023-11-07T05:31:56Z",
"payload": {}
}
],
"created_at": "2023-11-07T05:31:56Z",
"scheduled_at": "2023-11-07T05:31:56Z",
"inline_css": true,
"sandbox": true,
"recipient_statuses": {
"delivered": 998,
"bounced": 2
}
}
],
"errors": [
{
"index": 1,
"message": "<string>"
}
],
"meta": {
"total": 1,
"succeeded": 1,
"failed": 1
}
}{
"errors": [
{
"code": "10015",
"title": "Bad Request",
"detail": "email is required"
}
]
}{
"errors": [
{
"code": "10006",
"title": "Not authorized",
"detail": "Invalid API key",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10006"
}
}
]
}{
"errors": [
{
"code": "10036",
"title": "Resource is being processed",
"detail": "A request with this Idempotency-Key is already being processed.",
"source": {
"pointer": "/header/Idempotency-Key"
}
}
]
}{
"errors": [
{
"code": "10007",
"title": "Unexpected error",
"detail": "An unexpected error occured."
}
]
}{
"errors": [
{
"code": "10027",
"title": "Unprocessable Entity",
"detail": "The server understood the syntax of the request but was unable to process the instructions."
}
]
}{
"errors": [
{
"code": "reputation_suspended",
"title": "Sending Suspended",
"detail": "<string>"
}
]
}{
"errors": [
{
"code": "10016",
"title": "Service Unavailable",
"detail": "The email domain service is temporarily unavailable. Please try again later."
}
]
}