Replace eSIM (new number)
Swap a phone-number line for a new number, free of charge — for when the number your customer received is still registered to someone else's WhatsApp, Telegram or Apple ID.
- Phone-number lines only, within 3 days of purchase, and once per order. Anything more goes through support.
- The old eSIM stops working. Your customer must install the new eSIM (new QR code / activation code).
Endpoints
GET /api/v1/business/esims/replace?iccid=<iccid> (can it be replaced now?)
POST /api/v1/business/esims/replace (replace)
AI prompt — Replace eSIM (new number)
Paste into ChatGPT, Claude, Cursor, Copilot or any coding agent to generate this part of your integration. Built-in recommendation: Support action within 3 days of purchase: swap an unusable number, store the new line and send the new QR at once.
Show prompt text (46 lines)
# eSIMfly Business API — Replace eSIM / new number (GET/POST /esims/replace) — prompt for AI coding assistants
TASK: let support swap a phone-number line for a NEW number, free, when the number the customer received is
still registered to someone else's WhatsApp / Telegram / Apple ID. Allowed within 3 days of purchase and once
per order. The old eSIM stops working; the customer must install the new one.
COMMON RULES (apply to every eSIMfly request)
- Base URL: https://esimfly.net/api/v1/business
- Headers on every call: RT-AccessCode (esf_...), RT-RequestID (fresh UUID v4 per request; reuse -> 400 DUPLICATE_REQUEST),
RT-Timestamp (ms since epoch; >5 min old -> 401 INVALID_TIMESTAMP),
RT-Signature = UPPERCASE hex HMAC-SHA256(secretKey, timestamp + requestId + accessCode + rawBody).
rawBody = "" for GET; for POST/PUT sign the exact body string you send, with Content-Type: application/json.
- Keep access code + secret key server-side in env vars. Never ship them to a browser or mobile app.
- Responses: { success: true, ... } or { success: false, message, code }. Branch on `success` and `code`.
- Full multi-endpoint prompt: https://docs.esimfly.net/llm/esimfly-api-full-prompt.txt
ENDPOINTS
GET https://esimfly.net/api/v1/business/esims/replace?iccid=<iccid> (or ?esimId=)
-> { success: true, data: { iccid, esimId, replaceable, reason|null, availableUntil } }
POST https://esimfly.net/api/v1/business/esims/replace
Body: { "iccid": "8944110068223459012", "reason": "Number linked to another WhatsApp account" } // reason optional
RESPONSE 200
{ success: true, message: "Number replaced. Install the new eSIM - the old one no longer works.",
data: { previous: { iccid, esimId, phoneNumber },
esim: { iccid, esimId, phoneNumber, activationCode, qrCodeUrl, appleInstallUrl, androidInstallUrl, expiresAt },
duplicate } }
duplicate: true = this line was already replaced (e.g. a retry after a timeout); the same new line is returned.
ERRORS: 400 MISSING_IDENTIFIER; 400 NOT_REPLACEABLE (show message: >3 days, cancelled, no numbers available...);
403 ACCOUNT_SUSPENDED; 404 ESIM_NOT_FOUND; 409 REPLACE_LIMIT (already replaced once - contact support);
409 REPLACE_IN_PROGRESS; 500/502 REPLACE_FAILED (the current number still works).
INTEGRATION PATTERN
1. Offer "Replace number" only for phone-number lines (can_extend = true) during their first 3 days; GET first
and show availableUntil / reason.
2. Confirm with the operator that the old eSIM stops working, then POST once.
3. On success: mark the old esims row replaced, insert the new line (iccid, esimId, phoneNumber, activationCode)
linked to the same order, and send the customer the new QR code / install links right away.
4. On timeout: POST again with the same iccid - the API returns duplicate: true with the same new line, never a
second one.
DELIVERABLE: getReplaceEligibility(iccid) + replaceLine(iccid, reason) in the shared client, the support action,
and the esims bookkeeping + customer notification.
Authentication
This endpoint requires HMAC authentication. See Authentication for details.
Check eligibility (GET)
Query parameters: iccid, or esimId instead.
{
"success": true,
"data": {
"iccid": "8944110068223459012",
"esimId": 33796,
"replaceable": true,
"reason": null,
"availableUntil": "2026-11-29T10:12:00.000Z"
}
}
Replace (POST)
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| iccid | String | Yes* | The ICCID of the line to replace |
| esimId | Integer | Yes* | The eSIM id (used if iccid is not provided) |
| reason | String | No | Why (max 300 characters), e.g. "Number linked to another WhatsApp account" |
* Provide either iccid or esimId.
Success Response (200 OK)
{
"success": true,
"message": "Number replaced. Install the new eSIM - the old one no longer works.",
"data": {
"previous": { "iccid": "8944110068223459012", "esimId": 33796, "phoneNumber": "447874273393" },
"esim": {
"iccid": "8944110068223460871",
"esimId": 33812,
"phoneNumber": "447874281120",
"activationCode": "LPA:1$smdp.example.com$ABCD-1234",
"qrCodeUrl": "data:image/png;base64,iVBORw0KGgo...",
"appleInstallUrl": "https://esimsetup.apple.com/esim_qrcode_provisioning?carddata=...",
"androidInstallUrl": "https://esimsetup.android.com/esim_qrcode_provisioning?carddata=...",
"expiresAt": "2026-12-28T09:40:00.000Z"
},
"duplicate": false
}
}
The new line takes over the order: order lookups, usage and renewals now refer to the new eSIM. Store the new iccid / esimId and deliver the new activation code to your customer.
duplicate: true means this line was already replaced (for example, you retried after a timeout); the same new line is returned and nothing new is bought.
Error Responses
| HTTP | code | When |
|---|---|---|
| 400 | MISSING_IDENTIFIER | Neither iccid nor esimId |
| 400 | NOT_REPLACEABLE | Not allowed now — see message (e.g. more than 3 days after purchase, line cancelled, no new numbers available) |
| 403 | ACCOUNT_SUSPENDED | The account is suspended |
| 404 | ESIM_NOT_FOUND | Not your eSIM, or not a phone-number line |
| 409 | REPLACE_LIMIT | Already replaced once on this order — contact support |
| 409 | REPLACE_IN_PROGRESS | A replacement of this line is running right now |
| 500/502 | REPLACE_FAILED | No new number could be issued; your current number still works |