Postal-compatible API (/api/v1)
Karta speaks the sending part of Postal's legacy HTTP API, so applications using Postal's client libraries keep working after changing the host and the key. Karta's tests are ported from Postal's request specs.
Moving from Postal
| Postal | Karta | |
|---|---|---|
| Base URL | https://postal.example.com/api/v1 | https://karta.example.com/api/v1 |
| Key | the server's API credential, in X-Server-API-Key | a Karta API key (karta_...) of the server, in X-Server-API-Key |
| Message ids | integers, one message per recipient | UUIDs: the id of a recipient of a Karta message |
| Statuses | Postal's | Pending, Sent, SoftFail, HardFail and Held only |
| From address | must be authorised for the server | must be at a verified domain of the organisation |
Steps:
- Create the organisation, server and domain in Karta and verify the domain (Managing organisations, servers and keys).
- Create an API key with
messages:sendandmessages:read(the default). - Point the client at Karta's host with the new key.
- Store message ids as strings: they are UUIDs now.
Endpoints Karta serves: send/message, send/raw, messages/message,
messages/deliveries. Any other /api/v1 path is not served (404).
Requests and answers
As in Postal:
Every endpoint accepts any HTTP method (clients use
POST).Parameters are read from the JSON body when
Content-Typeisapplication/json; otherwise from aparamsfield (form data or query string) holding a JSON object; otherwise there are none.Every answer is HTTP
200with this envelope:{"status": "success", "time": 0.011, "flags": {}, "data": {...}}statusissuccess,error(withdata.codeanddata.message) orparameter-error(withdata.message);timeis the seconds taken.
Two answers Postal never gives use a real HTTP status as well: a rate
limit (429, TooManyRequests, with Retry-After) and a temporary
failure to store or read a message (503, TemporaryFailure).
Authentication
X-Server-API-Key: <key>.
data.code | When |
|---|---|
AccessDenied | no key ("Must be authenticated as a server."), or the key lacks the scope |
InvalidServerAPIKey | the key is wrong or revoked |
ServerSuspended | the server is suspended |
send/* need messages:send; messages/* need messages:read.
POST /api/v1/send/message
| Parameter | Notes |
|---|---|
to, cc, bcc | arrays, or comma-separated strings; at most 50 each |
from | required; must be at a verified domain |
sender | must be at a verified domain |
reply_to | one address |
subject | |
plain_body, html_body | at least one |
tag | |
headers | object; numbers are accepted as values; fields Karta writes itself are refused |
attachments | array of {"name", "content_type", "data"} (data base64; content_type default application/octet-stream); entries that are not objects are skipped |
Other parameters are ignored. Postal's checks come in Postal's order:
data.code | Message |
|---|---|
NoRecipients | There are no recipients defined to receive this message |
TooManyToAddresses | The maximum number of To addresses has been reached (maximum 50) |
TooManyCCAddresses | ... CC addresses ... (maximum 50) |
TooManyBCCAddresses | ... BCC addresses ... (maximum 50) |
NoContent | There is no content defined for this e-mail |
FromAddressMissing | The From address is missing and is required |
AttachmentMissingName | An attachment is missing a name |
AttachmentMissingData | An attachment is missing data |
UnauthenticatedFromAddress | The From address is not authorised to send mail from this server |
A value of the wrong type, an invalid recipient address or an invalid header
is a parameter-error.
{
"to": ["bob@example.net"],
"from": "Ann <ann@example.com>",
"subject": "Your order",
"plain_body": "Thank you for your order.",
"tag": "receipts"
}{
"data": {
"message_id": "01a1bbdc-7383-7d51-9c3a-63d38f4883ba@karta.example.com",
"messages": {
"bob@example.net": {"id": "01a1bbdc-7386-742b-bd94-e3f3d85e3efe", "token": "hm2iys44vfhpbaep"}
}
},
"flags": {},
"status": "success",
"time": 0.011
}message_id is the Message-ID without angle brackets. messages maps
each recipient to its id (a recipient id, used by messages/*) and a
token (derived from the id; clients pass it back unread).
POST /api/v1/send/raw
| Parameter | Notes |
|---|---|
mail_from | required; the envelope sender, at a verified domain |
rcpt_to | required; array of addresses |
data | required; the message, base64 |
The message's From and Sender are checked too. With an empty rcpt_to,
nothing is sent and the answer is {"message_id": null, "messages": {}}.
message_id is null when the message has no Message-ID; Karta does
not add one to a raw message.
Parameter errors: "rcpt_to parameter is required but is missing",
"mail_from parameter is required but is missing", "data parameter is
required but is missing", "data parameter is not valid base64",
"data parameter is not a valid message". An envelope sender at another
domain gives UnauthenticatedFromAddress ("The envelope sender (mail_from)
is not authorised to send mail from this server").
POST /api/v1/messages/message
| Parameter | Notes |
|---|---|
id | required; a recipient id from send/* (a string or an integer, as in Postal; anything else is a parameter error) |
_expansions | true for all, or a list of: status, details, inspection, plain_body, html_body, attachments, headers, raw_message, activity_entries |
{"id": "01a1bbdc-7386-742b-bd94-e3f3d85e3efe", "_expansions": ["status", "details"]}{
"data": {
"details": {
"bounce": false,
"bounce_for_id": 0,
"direction": "outgoing",
"mail_from": "ann@example.com",
"message_id": "01a1bbdc-7383-7d51-9c3a-63d38f4883ba@karta.example.com",
"rcpt_to": "bob@example.net",
"received_with_ssl": null,
"size": "468",
"subject": "Your order",
"tag": "receipts",
"timestamp": 1794153149.317006
},
"id": "01a1bbdc-7386-742b-bd94-e3f3d85e3efe",
"status": {
"held": false,
"hold_expiry": null,
"last_delivery_attempt": null,
"status": "Pending"
},
"token": "hm2iys44vfhpbaep"
},
"flags": {},
"status": "success",
"time": 0.002
}Expansions:
| Expansion | Contents |
|---|---|
status | status (Pending queued, SoftFail deferred, Sent delivered, HardFail bounced, Held suppressed), last_delivery_attempt (Unix time), held (true when suppressed), hold_expiry (always null) |
details | envelope, subject, Message-ID, Unix timestamp, direction, size (a string, as in Postal), tag; bounce is always false and received_with_ssl null |
inspection | always "not inspected": Karta does not scan outgoing mail |
plain_body, html_body | the text and HTML parts |
attachments | filename, content_type, data (base64), size, hash (SHA-1, a checksum) |
headers | header fields by lower-case name, each a list of decoded values |
raw_message | the stored message, base64 (with Karta's Received: field) |
activity_entries | loads (opens) and clicks (with url), each with ip_address (the client's network), user_agent and an ISO 8601 timestamp |
An unknown id gives MessageNotFound ("No message found matching
provided ID", with the id).
POST /api/v1/messages/deliveries
id as above. Returns the recipient's delivery attempts, oldest first:
{
"data": [
{
"details": "250 2.0.0 Ok: queued as 4XyZ",
"id": "01a1bbdc-7280-7fbf-893b-98bee3baea2e",
"log_id": null,
"output": "250 2.0.0 Ok: queued as 4XyZ",
"sent_with_ssl": true,
"status": "Sent",
"time": null,
"timestamp": 1794153149.056123
}
],
"flags": {},
"status": "success",
"time": 0.002
}status is Sent, SoftFail or HardFail; output is the server's
reply as it wrote it, or null when no server replied (then details says
what Karta decided); log_id and time are always null.
Not available
Postal's other endpoints are not served, nor are routes, credentials over the API, or the click-tracking image proxy. Use the Karta API for credentials, suppressions and webhooks.
Webhooks
Karta sends webhooks in Postal's format (MessageSent, MessageDelayed,
MessageDeliveryFailed, MessageHeld, MessageLoaded,
MessageLinkClicked, DomainDNSError), signed with
X-Postal-Signature, X-Postal-Signature-256 and
X-Postal-Signature-KID under the key of the webhook's organisation,
whose public key is at that organisation's JWK set (one key per
organisation, not one per installation; a request of one organisation
does not verify with another's key). Add them over the Karta API with
"format": "postal"; their message.id and token are those this API
returns. What differs from Postal:
Webhooks.