Send API: one POST and your message is queued
You send a JSON request to api.sendpier.com. We accept the message and put it in the queue. You get one identifier back per message, which you can use later to look up the status of that message.
What you use it for
You use the API for code you manage yourself. It gives you things SMTP cannot.
-
An identifier per message
You get one identifier back per message. Store that msg_ number next to your own order or user number. You can then always trace what happened to that one message.
-
Templates from your server
You send only the template number and the values to fill in, such as the customer name and the order number. That is also the safest way: a value lands in the template as plain text and cannot break your layout.
-
Steering per message
Pick your message stream per message, switch tracking on or off, or send an attachment along. An attachment travels as base64: a way to put a file into the request as plain text. Over SMTP those choices are fixed per domain name.
Your first request
These are the example files from our knowledge base. They use no framework and no extra packages: only what your language already ships with.
cURL
curl -X POST "https://api.sendpier.com/v1/messages" \
-H "Authorization: Bearer sp_live_YOUR_KEY" \
-H "X-Domain-Name: yourdomain.com" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"from": { "email": "noreply@yourdomain.com" },
"to": [{ "email": "recipient@example.org" }],
"subject": "Hello from the Send API",
"text": "This works.",
"html": "<p>This works.</p>"
}'
PHP
$body = json_encode([
'from' => ['email' => 'noreply@yourdomain.com'],
'to' => [['email' => 'recipient@example.org']],
'subject' => 'Hello from the Send API',
'text' => 'This works.',
], JSON_THROW_ON_ERROR);
$handle = curl_init('https://api.sendpier.com/v1/messages');
curl_setopt_array($handle, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $body,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer '.getenv('SENDPIER_API_KEY'),
'X-Domain-Name: yourdomain.com',
'Content-Type: application/json',
'Accept: application/json',
],
]);
$raw = curl_exec($handle);
$status = curl_getinfo($handle, CURLINFO_RESPONSE_CODE);
Node.js
const response = await fetch('https://api.sendpier.com/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SENDPIER_API_KEY}`,
'X-Domain-Name': 'yourdomain.com',
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
from: { email: 'noreply@yourdomain.com' },
to: [{ email: 'recipient@example.org' }],
subject: 'Hello from the Send API',
text: 'This works.',
}),
signal: AbortSignal.timeout(30_000),
});
console.log(response.status, await response.text());
Python
import json, os, urllib.request
payload = json.dumps({
"from": {"email": "noreply@yourdomain.com"},
"to": [{"email": "recipient@example.org"}],
"subject": "Hello from the Send API",
"text": "This works.",
}).encode()
request = urllib.request.Request(
"https://api.sendpier.com/v1/messages",
data=payload,
method="POST",
headers={
"Authorization": "Bearer " + os.environ["SENDPIER_API_KEY"],
"X-Domain-Name": "yourdomain.com",
"Content-Type": "application/json",
"Accept": "application/json",
},
)
with urllib.request.urlopen(request, timeout=30) as response:
print(response.status, response.read().decode())
Any sender address on a verified domain name can be used to send email
What you get back
HTTP/1.1 202 Accepted
{
"object": "list",
"data": [
{
"object": "message",
"id": "msg_5f1c9a0b7e2d…",
"to": "recipient@example.org",
"status": "queued"
}
]
}
202 means accepted for delivery, not delivered. Whether the message arrived you look up later with the identifier, or we tell you through a webhook.
What you do with that identifier
- That same msg_ identifier is in every webhook about this message. It tells you which notification belongs to which message.
- A webhook also carries our own spid_ identifier, for example spid_7f3a2c. Quote that when you email support: it is how we find the same message in our logs.
Signing in with your key
Every request carries two headers: your key and your domain name. A header is an extra line at the top of the request, separate from the content.
The Send API key
Authorization: Bearer sp_live_YOUR_KEY
X-Domain-Name: yourdomain.com
- A key starts with sp_live_ and belongs to one domain name. Send from three domain names and you have three keys.
- X-Domain-Name has to be exactly that domain name. If it does not match, you get a 403 back. That way you notice a mistake straight away, instead of months later.
- from.email lives on that same domain. Otherwise you get a 422.
- The key is shown once. Keep it on your server outside your source code, for example in a .env file or a password vault. Never put it in code that ends up in a browser.
There is a second kind of key
For managing your suppressed addresses and your webhooks there is an account token. It works on cp.sendpier.com, covers your whole account and needs no X-Domain-Name. The two are not interchangeable. A domain key does not work on the account endpoints, and an account token does not work on the Send API.
The status API has no key
status.sendpier.com is public. No Authorization header belongs there, and sending a key changes nothing.
What the limits are
Two kinds of limit both produce a 429, and you do something completely different about each. The first says you are going too fast, the second says your balance is gone.
- 120 requests per minute per key
- The counter runs per clock minute and per key, not per IP address and not per account. No header comes back telling you how long to wait; count on the rest of the current minute. Every request counts, a GET included.
- 10 recipients per request
- That is the maximum, not a recommendation. Ten recipients in one request are ten messages, each with its own identifier. With one recipient per request you know the status per message. One bad address then cannot take the rest of your send down with it.
- 25 MB per message, 20 attachments
- Message and attachments together, measured as the real file size and so not as the longer base64 text. If one attachment is refused, we refuse the whole message.
- 500 a month per domain name, and a daily limit that grows
- The monthly quota is 500 per domain name on every plan. Clipper and Fleet add bonus credits every month for your whole account, and above that you top up with credits. Every domain name starts at 100 emails a day. That daily limit grows as long as your email arrives well. You can mail anyone straight away; only the number per day goes up gradually. Credits do not raise the daily limit. The day runs from midnight to midnight in UTC, universal time.
- Check your usage before a large send
- Once your balance is gone, we refuse every next message until the new month starts or you buy credits. Better to find that out beforehand than halfway through.
- Only retry on 429 and 503
- On a 429 or a 503, try again with a longer wait each time. A 422 comes back exactly the same however often you try. Log the status code and the response body on every error. The code in that body shows you what to change.
- Stop trying after a 401
- A 401 means your key is wrong. Keep trying and it gets worse. Ten failed authentication attempts from the same IP address within five minutes earn that address a temporary 429 everywhere. Fix your key first, then wait a few minutes.
Send your first request
Create an account, verify your domain name and make a key. The free plan has no end date and needs no credit card.