Developers
SMS verification API
Everything the dashboard does, from your own software: check prices, buy a number, read the code, cancel for a refund. Same balance, same prices, one endpoint.
Getting started
- Create an account and top up your balance.
- In Settings → API, request API access and say what you will use it for. Access is approved per account.
- Once approved, create a key there. It starts with
nsk_live_and is shown once: store it in an environment variable, never in a URL or in browser code.
Every request is a POST https://ninjasms.shop/api/sms with the key in Authorization: Bearer … and a JSON body { "operation": "…", "input": { … } }. Success is { ok: true, data }; a refusal is an HTTP error with { error, code? }. Prices are in US dollars.
Examples
Balance
curl -s https://ninjasms.shop/api/sms \
-H "Authorization: Bearer $NSK_KEY" \
-H "Content-Type: application/json" \
-d '{"operation":"balance.read"}'Returns { ok: true, data: { balance } }.
Prices
curl -s https://ninjasms.shop/api/sms \
-H "Authorization: Bearer $NSK_KEY" \
-H "Content-Type: application/json" \
-d '{"operation":"catalog.prices","input":{"service":"wa","country":2}}'Your price and stock per country and service: data[country][service] = { price, count }. Omit country for every country.
Buy a number
curl -s https://ninjasms.shop/api/sms \
-H "Authorization: Bearer $NSK_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1c2a4e-order-1042" \
-d '{"operation":"activation.purchase","input":{"service":"wa","country":2,"expectedPrice":0.13}}'Send the price you quoted as expectedPrice, as a number or a numeric string: if the price has risen past it the purchase is refused with 409 price_changed and nothing is charged. Leave expectedPrice out and the check is skipped, so you are charged the current price; a value that is not a number is refused with 400 bad_expected_price. "operator" is optional: leave it out to buy on any mobile operator. An Idempotency-Key is required (400 idempotency_key_required without one): use one per order and keep it for every retry of that order — a retry with the same key never buys a second number. Only drop the key after a success or a 409 already_completed, which includes the number that order bought.
Check for the code
curl -s https://ninjasms.shop/api/sms \
-H "Authorization: Bearer $NSK_KEY" \
-H "Content-Type: application/json" \
-d '{"operation":"activation.status","input":{"id":"123"}}'Use the id from the purchase response. Poll every few seconds until the code arrives. A response with note "confirming with the carrier" means a refund check is still pending: keep polling.
Cancel
curl -s https://ninjasms.shop/api/sms \
-H "Authorization: Bearer $NSK_KEY" \
-H "Content-Type: application/json" \
-d '{"operation":"activation.transition","input":{"id":"123","transition":"cancel"}}'Refunds the number. Cancelling opens 2 minutes after purchase and closes once a code has arrived. Use "complete" once you have the code.
Client libraries
One file each, no dependencies, with this site’s address already in it. Every operation below is a method. A purchase takes your own id for the order as its Idempotency-Key, and a retry with the same id can never buy twice. waitForCode / wait_for_code polls until the code arrives.
- ninjasms.js · JavaScript for Node 18+, Deno or Bun
- ninjasms.py · Python 3.8+, standard library only
import { Client } from './ninjasms.js';
const api = new Client(process.env.NSK_KEY);
const number = await api.buy('wa', 2, 0.13, {}, 'order-1042');
console.log(await api.waitForCode(number.id));Keep the key on a server: never put it in a web page or an app.
Sandbox keys
Tick Sandbox key when creating a key in Settings → API to build and test without spending. A sandbox key takes the same requests and gives the same answers, with three differences: the numbers are made up, a code arrives 20 seconds after buying, and nothing is ever charged (the balance it reports is a fixed 100.00). Services, countries and prices are the real ones. Reactivation and replacement answer not_available. Every sandbox answer carries "sandbox": true.
Retries never buy twice
Every purchase needs an Idempotency-Key header, one per order (a UUID or your own order number). If a request times out or your connection drops, send the same request with the same key: you get the number that order already bought, never a second one.
Keep the key until the outcome is final: a success, or 409 already_completed. On 409 in_progress wait and retry with the same key; on 409 uncertain stop and contact support, keeping the key. After price_changed, no_numbers_at_price or a 402, nothing was charged — re-read the price and retry with the same key.
Send the price you were shown as expectedPrice. If the price has risen past it, the purchase is refused and nothing is charged, so you are never billed more than you agreed to. The value may be a number or a numeric string; if you leave it out, that check is skipped and you are charged the current price.
Operations
| Operation | Input | What it does |
|---|---|---|
| balance.read | — | Your balance. |
| catalog.services | — | The services on sale, with their codes. |
| catalog.countries | — | The countries, with their ids. |
| catalog.prices | { service, country?, type?, duration? } | Your price and stock. type is sms (default), call or rent; a rental also needs duration in hours. |
| activation.purchase | { service, country, expectedPrice, operator?, type?, duration?, phoneException? } | Buy one number. Needs an Idempotency-Key header. For several numbers, send several purchases, each with its own key. |
| activation.status | { id } | One number and its code, once it has arrived. |
| activation.messages | { id } |
Webhooks
Instead of polling for codes, set a webhook under Settings → API. Each event is POSTed to your https endpoint as JSON the moment it happens: activation.code (activation_id, service, phone, code) and deposit.credited (reference, amount).
Every request carries X-Webhook-Signature: t=<unix>,v1=<hex>: an HMAC-SHA256 of t.body with your signing secret. Check it, and reject a timestamp older than five minutes, before trusting the event. Answer 2xx within five seconds; a failed event is retried after 1, 5, 15, 60 and 180 minutes with the same id, so drop repeats. Ten failures in a row, or a 410, pause the webhook.
Standard handler API
Tools and bots built for the common handler API format used by SMS-verification tools work here unchanged: point them at https://ninjasms.shop/stubs/handler_api.php and use your API key as api_key. It runs on the same account, balance, prices and checks as /api/sms; only the request and answer format differ.
Supported actions: getBalance, getNumber, getNumberV2, getStatus, setStatus (6 complete, 8 cancel, 1 ready), getActiveActivations, getPrices, getCountries and getServicesList. Answers are the usual tokens — ACCESS_NUMBER:id:phone, STATUS_WAIT_CODE, STATUS_OK:code, ACCESS_CANCEL — and refusals such as BAD_KEY, NO_BALANCE, NO_NUMBERS, WRONG_MAX_PRICE, EARLY_CANCEL_DENIED, PURCHASE_PENDING (do not buy again; check your numbers) and SERVICE_UNAVAILABLE. setStatus=3 is not supported: a second code is a paid reactivation, available through /api/sms.
Retries: this format has no idempotency key, so each getNumber is a new purchase. If your tool can, send idempotency_key (one per order, kept for every retry) and a retry returns the number that order already bought. Send maxPrice and you are never charged more than it. Prefer a POST form body over the query string, so your key stays out of URLs and logs.
Errors
| Status | Code | What to do |
|---|---|---|
| 400 | idempotency_key_required | A purchase without an Idempotency-Key header. Add one per order. |
| 400 | bad_idempotency_key | The Idempotency-Key is not 1–128 characters of A–Z a–z 0–9 _ . : -. Send a key in that form. |
| 401 | invalid_api_key | The key is missing, revoked, or was revoked by a password change. Create a new one. |
| 402 | — | Not enough balance for this number. Top up and retry with the same key. |
| 403 | ip_not_allowed | The key is restricted to certain IP addresses and this request came from another. Call from an allowed address, or change the list in Settings → API. |
| 403 | api_access_inactive | API access is not active for the account. Request it in Settings → API. |
| 400 | bad_expected_price |