Guide · updated November 2026

Automate receiving SMS codes: polling or webhooks

By the Noir SMS team3 min read

Quick answer

The Noir SMS API gives you two ways to get the code automatically. Polling: call GET /api/v1/numbers/{id} every 3 to 5 seconds until status is received. Webhooks: set an HTTPS URL in the dashboard and receive a POST with type sms.received as soon as the SMS is detected. Verify the X-NoirSMS-Signature header, which is an HMAC-SHA256 of the timestamp and raw body, and reject events older than 5 minutes.

Polling is easiest for scripts. Webhooks scale better when many numbers are open at once.

Which to choose

PollingWebhook
SetupNonePublic HTTPS endpoint
LatencyYour polling intervalSeconds
Rate limit useOne request per pollNone
Best forScripts, CLI toolsPanels, bots, many numbers

Webhook receiver in Python

The header has the form t=<unix time>,v1=<signature>. We retry once after 3 seconds if your server fails, so respond with any 2xx quickly.

python
import hmac, hashlib, time, os
from flask import Flask, request, abort

app = Flask(__name__)
SECRET = os.environ["NOIRSMS_WEBHOOK_SECRET"]

def valid(raw: bytes, header: str) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    if abs(time.time() - int(parts["t"])) > 300:
        return False
    expected = hmac.new(SECRET.encode(), f"{parts['t']}.".encode() + raw, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts["v1"])

@app.post("/noirsms")
def hook():
    if not valid(request.get_data(), request.headers.get("X-NoirSMS-Signature", "")):
        abort(401)
    event = request.get_json()
    if event["type"] == "sms.received":
        d = event["data"]
        save_code(d["number_id"], d["sms"]["code"])  # your own storage
    return "", 204

Combine them

Use webhooks as the main path and a slow poll (for example every 30 seconds) as a fallback for missed deliveries.

Use it responsibly

Use the API only for your own legitimate accounts or apps you're authorized to test, and make sure your customers follow the same Acceptable Use Policy.

Frequently asked questions

Do webhooks fire for dashboard purchases?

Webhooks are for numbers bought through the API.

What if my endpoint is down?

We retry once. Keep a fallback poll for numbers still open.

Services in this guide

Keep reading

Ready to receive your code?

Create a free account, add funds from $5 and get your first verification code in under a minute.