# IMAP Migrator REST API

> Start and monitor IMAP migrations from your own tools. JSON over HTTPS. Machine-readable spec: https://whatsmyip.tr/openapi.json

Base URL: `https://whatsmyip.tr/api/v1`

Authentication: create a key under Account → API and send `Authorization: Bearer <key>` (or `X-API-Key: <key>`). Starting, cancelling and retrying need an active plan. Limit: 120 requests per minute, 5 running migrations.

## Endpoints

| Method | Path | Purpose |
|---|---|---|
| GET | /me | The account the key belongs to |
| POST | /preflight | Log in to every account pair and report per side |
| POST | /discover-folders | Folders of one source account with message counts |
| POST | /migrations | Start a migration |
| GET | /migrations | Recent runs (filters: status, limit) |
| GET | /migrations/{id} | Live totals, accounts and folders |
| GET | /migrations/{id}/events?after= | Action log lines, incremental |
| GET | /migrations/{id}/report | Per-folder report (also .csv and .pdf) |
| POST | /migrations/{id}/cancel | Stop after the current message |
| POST | /migrations/{id}/retry-failed | Copy failed messages again (within 24 h) |

## Start a migration

```bash
curl -X POST https://whatsmyip.tr/api/v1/migrations \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"srcHost":"mail.old.com","tgtHost":"outlook.office365.com","srcAccounts":"a@old.com\nsecret","tgtAccounts":"a@new.com\nsecret","accountConcurrency":3,"skipExisting":true,"autoMapSpecial":true}'
```

Fields: `srcHost`, `tgtHost` (required); `srcPort`/`tgtPort` (993); `srcSsl`/`tgtSsl` (true); `srcAccounts`/`tgtAccounts` (email and password on alternating lines, row order pairs accounts); `accountConcurrency` 1–10; `folderConcurrency` 1–5; `dryRun`; `skipExisting`; `deltaSync`; `forceRemigrate`; `since`/`before` (YYYY-MM-DD); `autoMapSpecial`; `excludedFolders` [{name}]; `folderMappings` [{sourceName, targetName}]; `messagesPerMinute`; `verify`; `scheduledAt` (ISO 8601); `clientName`.

## Webhooks

Set a URL under Account → Notifications to receive `migration.completed`, `migration.failed` or `migration.cancelled` with totals when a run ends.
