How do I send email with the Flyanote API?
Send each email as one POST /v1/messages request: one recipient, a sender, a subject, and a body, with an Idempotency-Key header so that a retry never sends it twice. Flyanote answers at once with the message's id, and sends it within seconds.
This is for transactional mail: receipts, password resets, and notifications. For a first test send, step by step, start with the quick start.
What does a send take?
from.address: an address on one of your verified domains or your Flyanote address, or, with a test key,test@sandbox.flyanote.com.from.nameis the name recipients see. Your sending domain says how to verify one.to: one recipient. To write to several people, send one message to each. Until the account has a verified domain and credit, it sends only to its own members' verified addresses; anyone else fails astier0_recipient_not_member.subject, and the body ashtml,text, or both. Withouttext, Flyanote makes one fromhtml. Each body can be up to 256 KiB, and the whole request up to 2 MiB.- If you want them:
reply_to, where replies go if not to the sender, never an address on one of Flyanote's own domains (leave it out when sending from your Flyanote address: its mail replies to the mailbox you confirmed for it);headers, onlyIn-Reply-To,References, andX-Entity-Ref-ID, to thread a reply or keep Gmail from grouping unrelated mail; andtags, up to 10 labels of your own that come back when you read the message. - An API key that can send: its scopes include
messages:send.
How do I send one?
With your key in FLYANOTE_API_KEY, and your own addresses in place of the example's:
curl -sS https://app.flyanote.com/api/v1/messages \
-H "Authorization: Bearer $FLYANOTE_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: receipt-1042" \
-d '{
"from": {"address": "receipts@example.com", "name": "Example Shop"},
"to": "jane@example.com",
"subject": "Your receipt for order 1042",
"html": "<p>Thanks for your order. It ships on Monday.</p>",
"tags": {"order": "1042"}
}'Make the Idempotency-Key something that names this one email for good, like your order number and what the email is for. A random UUID works too, as long as you keep it for the retries.
What does the answer mean?
202 Accepted, with the message's id and its status: queued means accepted and sending shortly, and suppressed means it won't be sent and isn't charged (the message's reason says why). Accepted isn't delivered: read the message to see what happened next.
A 4xx is a refusal, and nothing was sent; after a 5xx or a timeout, retry as below, since it may have been accepted. The refusals a working integration meets:
sender_not_ready(422): the sender isn't on a domain or Flyanote address of the account that has finished setting up.reply_to_unverified(422): the sender is your Flyanote address, and its reply-to mailbox isn't confirmed yet, orreply_toisn't that mailbox.reply_to_invalid(422):reply_tois on one of Flyanote's own domains, where replies can't go.validation_failed(422): a field is missing or wrong, and the answer'serrorssays which.insufficient_credit(402): the account's credit doesn't cover a live send.idempotency_key_reused(409): the key already names a different message.rate_limited(429): too many requests; wait theRetry-Afterseconds.
API errors lists every code with the steps that fix it, and the messages reference lists each one this request can answer.
How do I retry without sending twice?
Send the same body with the same Idempotency-Key. Once a request with that key is accepted, a retry within 24 hours answers the first 202 again, with the header Idempotent-Replayed: true, and sends nothing.
- After a timeout or any
5xx, retry with the same key and body: the message may have been accepted before the error. - After a
4xx, nothing was kept: fix the request, then send it again. - After a
409, the key already names another message, so the fixed request needs a new key.
How do I find out what happened to it?
Read it with GET /v1/messages/{id}, using a key whose scopes include messages:read. Put the id from the answer in place of msg_…:
export MESSAGE_ID='msg_…'
curl -sS "https://app.flyanote.com/api/v1/messages/$MESSAGE_ID" \
-H "Authorization: Bearer $FLYANOTE_API_KEY"- Its
statusgoesqueued,sending,sent, thendelivered, and can becomebouncedorcomplainedafter that. failedandsuppressedwere never sent.reason.codesays why, in a code to branch on, andreason.detailin words.- A test key's messages end as
test: they never deliver. eventslists what happened, oldest first: each event'stype(send,delivery,deferral,bounce,complaint, and the rest), when (at), and acodewhen there is one.
When reason.retryable is true, sending the same message again may work once reason.retry_after seconds have passed. Read it again first, since a late answer may have moved it on, then send it as a new request with a new Idempotency-Key.
How do I list what I've sent?
GET /v1/messages answers the newest first, 25 to a page by default and up to 100 with limit. Filter with status, created_after, and created_before. Each page's next_cursor goes in the next request's cursor, and it's null on the last page. Here, the bounces:
curl -sS "https://app.flyanote.com/api/v1/messages?status=bounced&limit=100" \
-H "Authorization: Bearer $FLYANOTE_API_KEY"