Receiving the code

Poll one order with /sms/check, every outstanding order with /request/active, or have codes pushed to you by webhook.

Embed
Preview of the card
<a href="https://numestri.com/docs/receiving-the-code"><img src="https://numestri.com/docs/_api/public/orgs/25229885-9620-4c08-bd2e-a0d0d74ac8b6/spaces/ef21e0c3-966d-4b03-b6d2-e66d449835d4/pages/5de7265f-1155-436a-87d7-b10b22f90b33/social-card.svg?v=3e7ae33eec8b" alt="Receiving the code" width="600" height="315"></a>

A code can arrive seconds or minutes after you order. There are two ways to get it: ask, or be told.

Polling

/sms/check answers for one order. It returns 200 for any order you own — branch on status, not on the HTTP code.

curl https://numestri.com/api/v1/sms/check -H "Authorization: Bearer $NUMESTRI_KEY" -d orderid=JRJ5UEXS
{ "status": 1, "resend": 0, "time_left": 1188 }

status

Meaning

1

Ready, waiting for the SMS. Request the code now.

2

Expired without a code. Refunded automatically.

3

A code arrived; it is in sms, the whole message in full_sms.

4

A resend was requested.

5

You cancelled the order (refunded).

6

Refunded.

7

Being fulfilled. Not ready to receive yet.

8

The number is being activated. Not ready to receive yet.

Poll every 3–5 seconds and stop on 3, 2, 5 or 6.

Wait for status 1 before requesting the code

Some numbers have to activate for a few minutes after purchase, and report 8 (activating) until they can receive. Do not ask the platform to send the code until the status is 1 — a code sent to a number that is still activating is lost. While it activates, ready_at_estimate gives the unix time such numbers are typically ready (or null when there is no estimate). time_left keeps counting down from purchase the whole time, and an order that never becomes ready is refunded at expiry like any other.

Many orders at once

/request/active returns every outstanding order in one call — the right choice once you have more than one in flight.

curl https://numestri.com/api/v1/request/active -H "Authorization: Bearer $NUMESTRI_KEY"
[
  { "order_code": "JRJ5UEXS", "phonenumber": "12025550123", "code": "140722", "status": "completed", "time_left": 1102 }
]

status is one of pending, processing, activating, completed, resend, expired, cancelled or refunded. processing and activating are not ready yet: wait for pending, using ready_at_estimate as a guide.

Before buying, /request/price lists each option's readiness: instant, or activates with the typical ready_in_seconds, plus how soon a first code usually lands.

A complete loop

const api = "https://numestri.com/api/v1";
const headers = { Authorization: `Bearer ${process.env.NUMESTRI_KEY}` };

const order = await fetch(`${api}/purchase/sms`, {
  method: "POST", headers, body: new URLSearchParams({ service: "telegram", country: "US" }),
}).then((r) => r.json());
if (!order.success) throw new Error(order.message);

let asked = false; // 7 / 8: activating, not ready to receive yet.
while (true) {
  const check = await fetch(`${api}/sms/check`, {
    method: "POST", headers, body: new URLSearchParams({ orderid: order.order_id }),
  }).then((r) => r.json());

  if (check.status === 1 && !asked) { /* Ready: ask the platform for the code now. */ asked = true; }
  if (check.status === 3) { console.log("code:", check.sms); break; }
  if ([2, 5, 6].includes(check.status)) throw new Error("No code; the order was refunded.");
  await new Promise((r) => setTimeout(r, 4000));
}
Updated