API リファレンス
メールを送信
公開済みテンプレートとアプリのデータでメールを送信します。
リクエスト
POST /api/v1/emails
| 項目 | 必須 | 説明 |
|---|---|---|
to |
はい | 宛先 1 件。最大 255 文字。 |
template |
はい | プロジェクト内のテンプレートキー。最大 100 文字。小文字の英字・数字・_・- を使い、先頭は英字または数字。 |
data |
はい | テンプレート変数のオブジェクト。変数がない場合は {}。 |
locale |
いいえ | ja や en-gb などの公開済み言語タグ。省略するとテンプレートの既定言語。 |
リクエスト例
公開済みテンプレートのキーと変数を使います。以下では welcome、name、action_url を使用します。
cURL
curl https://sendery.co/api/v1/emails \
-H "Authorization: Bearer $SENDERY_API_KEY" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Idempotency-Key: welcome-123' \
-d '{
"to": "[email protected]",
"template": "welcome",
"data": {"name": "Alex", "action_url": "https://example.com/start"}
}'PHP
require 'vendor/autoload.php';
use Sendery\Client;
$sendery = new Client(getenv('SENDERY_API_KEY'));
$receipt = $sendery->send(
to: '[email protected]',
template: 'welcome',
data: ['name' => 'Alex', 'action_url' => 'https://example.com/start'],
);
echo $receipt['id'];JavaScript
import { Sendery } from '@sendery/sdk';
const apiKey = process.env.SENDERY_API_KEY;
if (!apiKey) throw new Error('Set SENDERY_API_KEY on your server.');
const sendery = new Sendery(apiKey);
const receipt = await sendery.send({
to: '[email protected]',
template: 'welcome',
data: { name: 'Alex', action_url: 'https://example.com/start' },
});
console.log(receipt.id);Python
import os
from sendery import Sendery
sendery = Sendery(os.environ["SENDERY_API_KEY"])
receipt = sendery.send(
to="[email protected]",
template="welcome",
data={"name": "Alex", "action_url": "https://example.com/start"},
)
print(receipt["id"])Java
import co.sendery.Sendery;
import java.util.Map;
public class SendWelcome {
public static void main(String[] args) {
var sendery = new Sendery(System.getenv("SENDERY_API_KEY"));
var receipt = sendery.send("[email protected]", "welcome", Map.of(
"name", "Alex",
"action_url", "https://example.com/start"
));
System.out.println(receipt.id());
}
}Kotlin
import co.sendery.Sendery
fun main() {
val sendery = Sendery(System.getenv("SENDERY_API_KEY"))
val receipt = sendery.send("[email protected]", "welcome", mapOf(
"name" to "Alex",
"action_url" to "https://example.com/start"
))
println(receipt.id())
}レスポンス
新規送信は 202 と id、status を返します。同じ Idempotency-Key と内容で受付済みリクエストを再試行すると、200 と元の ID、現在の状態を返します。下書きの変更や再公開は受付済みメールには反映されません。
202 · application/json
{
"id": "35a6b227-1748-412e-8651-430492201670",
"status": "queued"
}変数と上限
テンプレートで使う変数をすべて指定します。値には文字列・数値・真偽値、または明細ブロック用のオブジェクト配列を使用できます。null とネストしたオブジェクトは使用できません。空文字列と空白は保持されます。
| 対象 | 上限 |
|---|---|
| JSON リクエスト本文 | 64 KiB(65,536 バイト) |
data の変数数 |
50 |
| 単一値 | 10,000 バイト |
| 配列の行数 | 100 |
| 1 行の項目数 | 10 |
| 行内の値 | 2,000 バイト |
明細ブロックには専用の項目が必要で、調整行は最大 20 行です。明細ガイドを参照してください。生成後のメールが大きすぎる場合は 422 を返します。繰り返し使う内容や長い変数を減らしてください。
送信者と内容
送信者はプロジェクト、件名と本文はテンプレートで設定します。リクエストに指定できる項目は to、template、data、locale のみです。html、subject、from、添付ファイル、cc、bcc、複数宛先には対応していません。