DEV Community

Cover image for How to Add SMS Verification to Your App in 5 Minutes (Python + Node.js)
Tony
Tony

Posted on

How to Add SMS Verification to Your App in 5 Minutes (Python + Node.js)

SMS verification is everywhere — Telegram, WhatsApp, Google, social networks. If you're building a service that needs to verify phone numbers programmatically, you need a reliable API.

In this tutorial, I'll show you how to integrate SMS verification into your app using Python and Node.js in under 5 minutes.

Why Programmatic SMS Verification?

Common use cases:

  • QA & Testing — verify signup flows without burning real phone numbers
  • Account Management — automate account creation for your SaaS platform
  • Multi-region Testing — test with phone numbers from 100+ countries
  • CI/CD Pipelines — automated end-to-end tests with real SMS

Prerequisites

You'll need an API key from SMSCodex. Sign up, go to API Access in your dashboard, and issue a key.

Python Example

import requests
import time

API_BASE = "https://smscodex.com/api/v1"
API_KEY = "your_api_key_here"

headers = {
    "Content-Type": "application/json",
    "X-Client-Api-Key": API_KEY,
}

# Step 1: Request a number
response = requests.post(
    f"{API_BASE}/marketplace/fast-purchase",
    headers=headers,
    json={
        "service_code": "telegram",
        "country": "US",
        "price_limit": 2.0,
        "currency": "USD",
    },
)
data = response.json()
print(f"Number: {data['display_number']}")
print(f"Order: {data['order_id']}")

# Step 2: Wait for SMS (poll every 5 seconds)
order_id = data["order_id"]
for _ in range(24):  # 2 minutes max
    time.sleep(5)
    status = requests.get(
        f"{API_BASE}/marketplace/orders/{order_id}",
        headers=headers,
    ).json()

    if status.get("sms_code"):
        print(f"SMS Code: {status['sms_code']}")
        break
else:
    print("Timeout — no SMS received")
Enter fullscreen mode Exit fullscreen mode

Node.js Example

const API_BASE = "https://smscodex.com/api/v1";
const API_KEY = "your_api_key_here";

async function getVerificationCode(service, country) {
  // Step 1: Request a number
  const res = await fetch(`${API_BASE}/marketplace/fast-purchase`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-Client-Api-Key": API_KEY,
    },
    body: JSON.stringify({
      service_code: service,
      country: country,
      price_limit: 2.0,
      currency: "USD",
    }),
  });

  const data = await res.json();
  console.log(`Number: ${data.display_number}`);

  // Step 2: Poll for SMS
  for (let i = 0; i < 24; i++) {
    await new Promise((r) => setTimeout(r, 5000));
    const status = await fetch(
      `${API_BASE}/marketplace/orders/${data.order_id}`,
      { headers: { "X-Client-Api-Key": API_KEY } }
    ).then((r) => r.json());

    if (status.sms_code) {
      console.log(`SMS Code: ${status.sms_code}`);
      return status.sms_code;
    }
  }
  throw new Error("Timeout");
}

// Usage
getVerificationCode("telegram", "US")
  .then((code) => console.log("Done:", code))
  .catch(console.error);
Enter fullscreen mode Exit fullscreen mode

Webhook Alternative (No Polling)

Instead of polling, you can set up a webhook in your dashboard to receive SMS codes instantly:

{
  "event": "sms_received",
  "order_id": "ord_01HZY7F4NNWJ8KZ3Q0VQW4R6KJ",
  "sms_code": "48291",
  "phone": "+1234567890",
  "service": "telegram",
  "received_at": "2026-04-03T12:30:42Z"
}
Enter fullscreen mode Exit fullscreen mode

Webhook payloads are signed with HMAC-SHA256 via the X-Notification-Signature header for security.

Error Handling

Key error codes to handle:

Code Meaning Action
number_not_found No numbers available Try different country
insufficient_funds Balance too low Top up account
rate_limit_exceeded Too many requests Wait and retry

Tips for Production

  1. Use idempotency keys — prevent duplicate purchases on retries
  2. Set price limits — avoid overpaying with price_limit parameter
  3. Handle timeouts — not every number receives SMS, build retry logic
  4. Use webhooks — more reliable than polling for high-volume use cases

What's Next?

  • Full API docs: smscodex.com/docs/fast-purchase
  • 200+ supported services (Telegram, WhatsApp, Google, Facebook, etc.)
  • Available in 100+ countries with instant delivery
  • Pricing starts from $0.01 per activation

If you have questions about the architecture, drop a comment below!

Top comments (0)