Examples

End-to-end snippets for common integrations. Replace placeholders with your values.

curl: create, wait, read OTP

bash
API="https://api.tempfoxmail.com"

# 1) create an inbox (anonymous)
RESP=$(curl -s -X POST $API/v1/inboxes -H "content-type: application/json" -d '{}')
ID=$(echo "$RESP" | jq -r .id)
TOKEN=$(echo "$RESP" | jq -r .capability_token)
echo "address: $(echo "$RESP" | jq -r .address)"

# 2) poll for the first message
MSG=$(curl -s "$API/v1/inboxes/$ID/messages" -H "X-Inbox-Token: $TOKEN" | jq -r '.data[0].id')

# 3) read its one-time passcode
curl -s "$API/v1/messages/$MSG/otp" -H "X-Inbox-Token: $TOKEN" | jq .otp

JavaScript / TypeScript (fetch)

typescript
const API = "https://api.tempfoxmail.com";

async function createInbox() {
  const res = await fetch(`${API}/v1/inboxes`, {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({}),
  });
  if (!res.ok) throw new Error((await res.json()).error.code);
  return res.json(); // { id, address, capability_token, ... }
}

async function listMessages(id: string, token: string) {
  const res = await fetch(`${API}/v1/inboxes/${id}/messages`, {
    headers: { "X-Inbox-Token": token },
  });
  return (await res.json()).data;
}

Developer key (Bearer)

bash
# Create your key in the account UI, then:
curl -X POST https://api.tempfoxmail.com/v1/inboxes \
  -H "Authorization: Bearer $LINDEN_API_KEY" \
  -H "content-type: application/json" \
  -d '{ "webhook_url": "https://your.app/hooks/linden" }'

Playwright: receive a signup OTP in a test

typescript
import { test, expect, request } from "@playwright/test";

const API = "https://api.tempfoxmail.com";

test("sign-up delivers an OTP", async ({ page }) => {
  const api = await request.newContext();

  // 1) disposable inbox
  const inbox = await (await api.post(`${API}/v1/inboxes`, { data: {} })).json();

  // 2) use its address in your product's sign-up form
  await page.goto("https://your.app/signup");
  await page.getByLabel("Email").fill(inbox.address);
  await page.getByRole("button", { name: "Sign up" }).click();

  // 3) poll TempFoxMail for the verification code
  await expect.poll(async () => {
    const list = await (await api.get(
      `${API}/v1/inboxes/${inbox.id}/messages`,
      { headers: { "X-Inbox-Token": inbox.capability_token } },
    )).json();
    if (list.data.length === 0) return null;
    const otp = await (await api.get(
      `${API}/v1/messages/${list.data[0].id}/otp`,
      { headers: { "X-Inbox-Token": inbox.capability_token } },
    )).json();
    return otp.otp;
  }, { timeout: 30000 }).not.toBeNull();
});