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

PostalKarta
Base URLhttps://postal.example.com/api/v1https://karta.example.com/api/v1
Keythe server's API credential, in X-Server-API-Keya Karta API key (karta_...) of the server, in X-Server-API-Key
Message idsintegers, one message per recipientUUIDs: the id of a recipient of a Karta message
StatusesPostal'sPending, Sent, SoftFail, HardFail and Held only
From addressmust be authorised for the servermust be at a verified domain of the organisation

Steps:

  1. Create the organisation, server and domain in Karta and verify the domain (Managing organisations, servers and keys).
  2. Create an API key with messages:send and messages:read (the default).
  3. Point the client at Karta's host with the new key.
  4. 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-Type is application/json; otherwise from a params field (form data or query string) holding a JSON object; otherwise there are none.

  • Every answer is HTTP 200 with this envelope:

    {"status": "success", "time": 0.011, "flags": {}, "data": {...}}

    status is success, error (with data.code and data.message) or parameter-error (with data.message); time is 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.codeWhen
AccessDeniedno key ("Must be authenticated as a server."), or the key lacks the scope
InvalidServerAPIKeythe key is wrong or revoked
ServerSuspendedthe server is suspended

send/* need messages:send; messages/* need messages:read.

POST /api/v1/send/message

ParameterNotes
to, cc, bccarrays, or comma-separated strings; at most 50 each
fromrequired; must be at a verified domain
sendermust be at a verified domain
reply_toone address
subject
plain_body, html_bodyat least one
tag
headersobject; numbers are accepted as values; fields Karta writes itself are refused
attachmentsarray 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.codeMessage
NoRecipientsThere are no recipients defined to receive this message
TooManyToAddressesThe maximum number of To addresses has been reached (maximum 50)
TooManyCCAddresses... CC addresses ... (maximum 50)
TooManyBCCAddresses... BCC addresses ... (maximum 50)
NoContentThere is no content defined for this e-mail
FromAddressMissingThe From address is missing and is required
AttachmentMissingNameAn attachment is missing a name
AttachmentMissingDataAn attachment is missing data
UnauthenticatedFromAddressThe 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

ParameterNotes
mail_fromrequired; the envelope sender, at a verified domain
rcpt_torequired; array of addresses
datarequired; 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

ParameterNotes
idrequired; a recipient id from send/* (a string or an integer, as in Postal; anything else is a parameter error)
_expansionstrue 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:

ExpansionContents
statusstatus (Pending queued, SoftFail deferred, Sent delivered, HardFail bounced, Held suppressed), last_delivery_attempt (Unix time), held (true when suppressed), hold_expiry (always null)
detailsenvelope, subject, Message-ID, Unix timestamp, direction, size (a string, as in Postal), tag; bounce is always false and received_with_ssl null
inspectionalways "not inspected": Karta does not scan outgoing mail
plain_body, html_bodythe text and HTML parts
attachmentsfilename, content_type, data (base64), size, hash (SHA-1, a checksum)
headersheader fields by lower-case name, each a list of decoded values
raw_messagethe stored message, base64 (with Karta's Received: field)
activity_entriesloads (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.