pip install requests
SMS_ACT_KEY=your_key python sms_act_example.py
import os
import time
import uuid
import requests
BASE_URL = "https://sms-act.net/sms/open-api/v1"
SESSION = requests.Session()
SESSION.headers["X-Access-Key"] = os.environ["SMS_ACT_KEY"]
def call(method, path, **kwargs):
resp = SESSION.request(method, BASE_URL + path, timeout=30, **kwargs)
body = resp.json()
if resp.status_code >= 400:
err = body["error"]
raise RuntimeError(f"{err['code']}: {err['message']} (requestId={err['requestId']})")
return body["data"]
# 1. Order a number. The Idempotency-Key makes network retries safe.
activation = call(
"POST",
"/activations",
json={"service": "wa", "countryId": 6},
headers={"Idempotency-Key": str(uuid.uuid4())},
)
print("Phone number:", activation["phoneNumber"])
# 2. Poll every 5 seconds until the code arrives (or give up after 15 minutes).
deadline = time.time() + 15 * 60
while activation["status"] == "waiting" and time.time() < deadline:
time.sleep(5)
activation = call("GET", f"/activations/{activation['id']}")
# 3. No code in time: cancel and get the credits back.
if activation["status"] == "waiting":
try:
activation = call("POST", f"/activations/{activation['id']}/cancel")
except RuntimeError:
# The code may have arrived just before cancelling; read the final state.
activation = call("GET", f"/activations/{activation['id']}")
if activation["status"] == "completed":
print("Code:", activation["code"])
else:
print("No code received; the activation was cancelled and the credits were returned.")
# Node.js 18+
SMS_ACT_KEY=your_key node sms_act_example.mjs
import { randomUUID } from "node:crypto";
const BASE_URL = "https://sms-act.net/sms/open-api/v1";
const ACCESS_KEY = process.env.SMS_ACT_KEY;
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function call(method, path, { body, headers = {} } = {}) {
const resp = await fetch(BASE_URL + path, {
method,
headers: { "X-Access-Key": ACCESS_KEY, "Content-Type": "application/json", ...headers },
body: body ? JSON.stringify(body) : undefined,
});
const json = await resp.json();
if (!resp.ok) {
const { code, message, requestId } = json.error;
throw new Error(`${code}: ${message} (requestId=${requestId})`);
}
return json.data;
}
// 1. Order a number. The Idempotency-Key makes network retries safe.
let activation = await call("POST", "/activations", {
body: { service: "wa", countryId: 6 },
headers: { "Idempotency-Key": randomUUID() },
});
console.log("Phone number:", activation.phoneNumber);
// 2. Poll every 5 seconds until the code arrives (or give up after 15 minutes).
const deadline = Date.now() + 15 * 60 * 1000;
while (activation.status === "waiting" && Date.now() < deadline) {
await sleep(5000);
activation = await call("GET", `/activations/${activation.id}`);
}
// 3. No code in time: cancel and get the credits back.
if (activation.status === "waiting") {
try {
activation = await call("POST", `/activations/${activation.id}/cancel`);
} catch {
// The code may have arrived just before cancelling; read the final state.
activation = await call("GET", `/activations/${activation.id}`);
}
}
if (activation.status === "completed") {
console.log("Code:", activation.code);
} else {
console.log("No code received; the activation was cancelled and the credits were returned.");
}