Code examples
Small, complete examples to copy. Set DROPLINE_TOKEN to a token first.
List mailboxes
curl
curl https://dropline.cleforyx.com/api/v1/mailboxes \
-H "Authorization: Bearer $DROPLINE_TOKEN"Node
const res = await fetch("https://dropline.cleforyx.com/api/v1/mailboxes", {
headers: { Authorization: `Bearer ${process.env.DROPLINE_TOKEN}` },
});
const { mailboxes } = await res.json();Python
import os, requests
r = requests.get(
"https://dropline.cleforyx.com/api/v1/mailboxes",
headers={"Authorization": f"Bearer {os.environ['DROPLINE_TOKEN']}"},
)
mailboxes = r.json()["mailboxes"]Search unread mail from someone
curl
curl "https://dropline.cleforyx.com/api/v1/mailboxes/$MB/messages?q=is:unread%20from:kofi" \
-H "Authorization: Bearer $DROPLINE_TOKEN"Node
const api = (path, init = {}) =>
fetch(`https://dropline.cleforyx.com/api/v1${path}`, {
...init,
headers: { Authorization: `Bearer ${process.env.DROPLINE_TOKEN}`, "Content-Type": "application/json", ...init.headers },
}).then(async (r) => {
const b = await r.json();
if (!r.ok) throw Object.assign(new Error(b.error.message), b.error);
return b;
});
const { mailboxes } = await api("/mailboxes");
const { messages } = await api(`/mailboxes/${mailboxes[0].id}/messages?q=is:unread`);Python
import os, requests
s = requests.Session()
s.headers["Authorization"] = f"Bearer {os.environ['DROPLINE_TOKEN']}"
base = "https://dropline.cleforyx.com/api/v1"
mb = s.get(f"{base}/mailboxes").json()["mailboxes"][0]["id"]
messages = s.get(f"{base}/mailboxes/{mb}/messages", params={"q": "is:unread from:kofi"}).json()["messages"]Send, safely retried
Needs mail.send (paid plans). With send approval on, the response is 202 pending_approval until you press Send in the inbox.
curl
curl -X POST https://dropline.cleforyx.com/api/v1/mailboxes/$MB/send \
-H "Authorization: Bearer $DROPLINE_TOKEN" -H "Content-Type: application/json" \
-H "Idempotency-Key: order-4471-shipped" \
-d '{"to":[{"address":"[email protected]"}],"subject":"Your order shipped","text":"It is on its way."}'Python
r = s.post(
f"{base}/mailboxes/{mb}/send",
json={"to": [{"address": "[email protected]"}], "subject": "Hi", "text": "Hello"},
headers={"Idempotency-Key": "hello-kofi-1"},
)
print(r.status_code, r.json()) # 202 {'status': 'pending_approval', ...} unless approval is off