DEV Community

SMSPing
SMSPing

Posted on Edited on Originally published at smsping.net

Migrating SMS-Activate API Code to a Compatible Endpoint (handler_api.php)

SMS-Activate has shut down. If you still have scripts built on its handler_api.php, you don't need to rewrite them. SMSPing exposes a compatible endpoint: the supported actions take the same parameters and return the same response strings.

Disclosure: I work on SMSPing.

1. Change the base URL

# before
BASE="https://api.sms-activate.org/stubs/handler_api.php"
# after
BASE="https://smsping.net/stubs/handler_api.php"
Enter fullscreen mode Exit fullscreen mode

2. Get an API key

  1. Create an account or sign in at smsping.net.
  2. Add balance. USDT (TRC20/ERC20/BEP20) is the main option; TRX, ETH and BNB are also supported. Minimum top-up $10.
  3. Go to Account Settings → API Management and generate a key. It starts with psk_ and is shown in full only once.
  4. Keep the key on your server (for example SMSPING_API_KEY), never in browser code or a public repo.

3. Test it

curl "$BASE?api_key=$SMSPING_API_KEY&action=getBalance"
# ACCESS_BALANCE:12.40

# buy a Telegram number in the United Kingdom (deducts real balance)
curl "$BASE?api_key=$SMSPING_API_KEY&action=getNumber&service=tg&country=16"
# ACCESS_NUMBER:1000123:447700900123   (or NO_NUMBERS)

curl "$BASE?api_key=$SMSPING_API_KEY&action=getStatus&id=1000123"
# STATUS_WAIT_CODE  …later…  STATUS_OK:12345
Enter fullscreen mode Exit fullscreen mode

Send api_key and action as query parameters (GET) or as a form or JSON body (POST). Use SMS-Activate numeric country IDs (16 UK, 187 USA, 6 Indonesia) and service codes (tg, wa, go). getCountries and getServicesList return the full mapped lists. The catalog covers 140+ countries and many popular apps.

Supported actions

Action Key Response
getBalance Yes ACCESS_BALANCE:12.40 (USD)
getNumber Yes ACCESS_NUMBER:id:phone. Params service, country, optional maxPrice. Picks the cheapest in-stock offer.
getNumberV2 Yes JSON: activationId, phoneNumber, activationCost, countryCode, activationTime, activationEndTime
getStatus Yes STATUS_WAIT_CODE, STATUS_OK:12345, STATUS_CANCEL
getStatusV2 Yes JSON with sms (dateTime, code, text) or null; call is always null
setStatus Yes 8 cancel → ACCESS_CANCEL; 6 finish → ACCESS_ACTIVATION; 1 → ACCESS_READY; 3 → ACCESS_RETRY_GET
getActiveActivations Yes JSON list of waiting and received activations
getPrices Yes JSON {country: {service: {cost, count}}}; pass country, service or both
getNumbersStatus Yes JSON like {"tg_0": "100"} for one country
getCountries No JSON keyed by SMS-Activate country ID
getServicesList No JSON {status, services: [{code, name}]}

When you cancel with setStatus=8 and no SMS has arrived, the charge is returned to your balance (once per order; balance is non-withdrawable). Repeating the cancel doesn't return it twice.

Errors come back as plain text with HTTP 200, as SMS-Activate clients expect: NO_KEY, BAD_KEY, BAD_ACTION, BAD_SERVICE, BAD_COUNTRY, BAD_STATUS, NO_NUMBERS, NO_BALANCE, NO_ACTIVATION, WRONG_MAX_PRICE, CHANNELS_LIMIT, BANNED, ERROR_SQL.

Python example

import os, time, requests

BASE = "https://smsping.net/stubs/handler_api.php"   # was https://api.sms-activate.org/stubs/handler_api.php
KEY = os.environ["SMSPING_API_KEY"]

def sa(action, **params):
    r = requests.get(BASE, params={"api_key": KEY, "action": action, **params}, timeout=30)
    r.raise_for_status()
    return r.text

print(sa("getBalance"))

resp = sa("getNumber", service="tg", country=16)      # spends balance
if not resp.startswith("ACCESS_NUMBER:"):
    raise SystemExit(resp)
_, activation_id, phone = resp.split(":")
print("Number:", phone)

for _ in range(120):                                  # local 10-minute limit
    status = sa("getStatus", id=activation_id)
    if status.startswith("STATUS_OK:"):
        print("Code:", status.split(":", 1)[1])
        sa("setStatus", id=activation_id, status=6)   # finish
        break
    if status != "STATUS_WAIT_CODE":
        raise SystemExit(status)
    time.sleep(5)
else:
    print(sa("setStatus", id=activation_id, status=8))  # cancel; charge returned to balance
Enter fullscreen mode Exit fullscreen mode

Node.js (18+) example

const BASE = "https://smsping.net/stubs/handler_api.php";
const KEY = process.env.SMSPING_API_KEY;

async function sa(action, params = {}) {
  const url = new URL(BASE);
  url.search = new URLSearchParams({ api_key: KEY, action, ...params });
  return (await (await fetch(url)).text()).trim();
}
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

const v2 = await sa("getNumberV2", { service: "wa", country: 187 }); // spends balance
if (!v2.startsWith("{")) throw new Error(v2);
const { activationId, phoneNumber } = JSON.parse(v2);
console.log("Number:", phoneNumber);

for (let i = 0; i < 120; i++) {
  const status = await sa("getStatus", { id: activationId });
  if (status.startsWith("STATUS_OK:")) {
    console.log("Code:", status.slice(10));
    await sa("setStatus", { id: activationId, status: 6 });
    process.exit(0);
  }
  if (status !== "STATUS_WAIT_CODE") throw new Error(status);
  await sleep(5000);
}
console.log(await sa("setStatus", { id: activationId, status: 8 }));
Enter fullscreen mode Exit fullscreen mode

Differences and limits to check before switching

  • Not supported: rentals (getRent*), voice-call verification, getMultiServiceNumber, additional-service and forwarding actions. These return BAD_ACTION.
  • operator, phoneException and forward are accepted but ignored.
  • getPrices needs at least one of country or service; with neither it returns BAD_SERVICE.
  • Unlisted countries and services return BAD_COUNTRY or BAD_SERVICE.
  • setStatus=1 and 3 are acknowledged; the number keeps waiting for SMS either way.
  • Prices are in USD; times are UTC, ISO 8601.
  • Rate limit: 60 requests per minute per account. Beyond that the endpoint returns ERROR_SQL. Poll getStatus every 5 seconds or slower.
  • Call it from your server; cross-origin browser requests are rejected.

Before buying, confirm the target service accepts the number type you pick.

Full reference: SMS-Activate compatible API docs · Price list

Originally published at smsping.net.

Top comments (0)