API

How to automate virtual number release and cleanup after OTP verification using SMSVerifier API scripts?

July 30, 2026 · 6 min read · 11 views
You can automate virtual number release and cleanup after OTP verification by using SMSVerifier's API to monitor SMS status and trigger release commands programmatically, optimizing resource usage and costs.

Why automate virtual number release and cleanup?

When you use virtual numbers for SMS OTP verification, each number is typically rented and locked to your session until you explicitly release it or it expires. Manually managing releases can lead to unused numbers lingering, wasted funds, and slower workflows. Automating release and cleanup after verification ensures your rented numbers are freed immediately after use, reducing costs and allowing for seamless reuse.

Important context.

SMSVerifier supports instant refunds for numbers where no SMS arrives within the timeout period, but only if you release the number promptly.

In addition, automated cleanup scripts can handle edge cases like failed verifications or blocked numbers, maintaining a clean pool of active numbers and avoiding unexpected failures in your verification pipeline.

SMSVerifier API endpoints for release and status checking

The SMSVerifier API provides key endpoints to manage your virtual numbers programmatically:

  • getStatus: Checks the status of your rented number, including whether an SMS has arrived, the code received, or if the number is blocked.
  • setStatus: Allows you to release the number manually by setting its status to "canceled" or "completed," freeing it for reuse and triggering refunds if applicable.

These endpoints form the basis of your automation logic by letting you monitor OTP delivery and release numbers as soon as verification concludes.

Pro tip.

Poll the 'getStatus' endpoint at short intervals (e.g., every 5-10 seconds) after renting a number to detect OTP arrival quickly and trigger release immediately.

Automating release on OTP receipt or timeout

The core of automation lies in your script logic that waits for the OTP and then releases the number. Here is a typical workflow:

  • Step 1 — Rent number via API Use the API to get a virtual number for your target service.
  • Step 2 — Submit number on target site Provide the rented number to the service requiring OTP verification.
  • Step 3 — Poll for OTP Periodically call 'getStatus' to check if the SMS with OTP has arrived.
  • Step 4 — Release number Immediately call 'setStatus' to cancel/release the number once OTP is received or timeout is hit.

Setting a reasonable timeout (e.g., 5-10 minutes) ensures your script doesn't wait indefinitely for an OTP and releases resources promptly.

Common pitfall.

Failing to release unused numbers after timeout leads to unnecessary charges and blocked resources, reducing your account’s efficiency.

Handling failed and blocked numbers in automation

Sometimes numbers may become blocked, banned by the target service, or fail to receive SMS at all. Your automated scripts should:

  • Detect failure or blocked status via the 'getStatus' response.
  • Immediately release such numbers with 'setStatus' to avoid further charges.
  • Optionally log or blacklist problematic numbers in your own system to avoid reuse.
Automation isn't just about speed — it's also about maintaining a clean pool of usable numbers.

By proactively managing these cases, you avoid wasting funds and reduce errors in your OTP verification pipeline.

Example scripts for release and cleanup

SMSVerifier offers API documentation and example code snippets to help you automate number release and cleanup. Below are simplified examples in popular languages illustrating the core logic.

bash
# Poll status
curl "https://smsverifier.com/stubs/handler_api.php?api_key=YOUR_API_KEY&action=getStatus&id=ORDER_ID"

# Release number
curl "https://smsverifier.com/stubs/handler_api.php?api_key=YOUR_API_KEY&action=setStatus&status=8&id=ORDER_ID"
python
import time
import requests

API_KEY = "YOUR_API_KEY"
ORDER_ID = "ORDER_ID"
BASE_URL = "https://smsverifier.com/stubs/handler_api.php"

def get_status():
    params = {"api_key": API_KEY, "action": "getStatus", "id": ORDER_ID}
    r = requests.get(BASE_URL, params=params)
    return r.text

def release_number():
    params = {"api_key": API_KEY, "action": "setStatus", "status": 8, "id": ORDER_ID}
    r = requests.get(BASE_URL, params=params)
    return r.text

timeout = 600  # seconds
start = time.time()

while True:
    status = get_status()
    if "STATUS_OK" in status:
        print("OTP received:", status)
        release_number()
        print("Number released.")
        break
    if time.time() - start > timeout:
        print("Timeout reached, releasing number.")
        release_number()
        break
    time.sleep(10)
javascript
const fetch = require('node-fetch');

const API_KEY = 'YOUR_API_KEY';
const ORDER_ID = 'ORDER_ID';
const BASE_URL = 'https://smsverifier.com/stubs/handler_api.php';

async function getStatus() {
  const url = `${BASE_URL}?api_key=${API_KEY}&action=getStatus&id=${ORDER_ID}`;
  const res = await fetch(url);
  return await res.text();
}

async function releaseNumber() {
  const url = `${BASE_URL}?api_key=${API_KEY}&action=setStatus&status=8&id=${ORDER_ID}`;
  const res = await fetch(url);
  return await res.text();
}

async function waitForOtp() {
  const timeout = 600000; // 10 minutes
  const interval = 10000; // 10 seconds
  const start = Date.now();

  while (true) {
    const status = await getStatus();
    if (status.includes('STATUS_OK')) {
      console.log('OTP received:', status);
      await releaseNumber();
      console.log('Number released.');
      break;
    }
    if (Date.now() - start > timeout) {
      console.log('Timeout reached, releasing number.');
      await releaseNumber();
      break;
    }
    await new Promise(r => setTimeout(r, interval));
  }
}

waitForOtp();

Best practices to optimize automation

Efficient polling

Poll the API at reasonable intervals (5-10 seconds) to balance response time and API usage limits.

💳

Prompt release

Release numbers immediately after OTP receipt or timeout to avoid unnecessary charges and enable refunds.

🔄

Handle retries gracefully

Implement retry logic for transient API errors and ensure your release commands run reliably.

📊

Monitor statistics

Track success rates, average delivery times, and refunds to continuously improve your automation script.

Automated number release is the backbone of cost-effective and scalable SMS OTP verification workflows.

Frequently asked questions

What is the purpose of automating virtual number release after OTP verification?
Automating virtual number release helps free up resources, reduce costs, and ensure numbers are available for reuse immediately after verification.
Which SMSVerifier API endpoints are used for number release and cleanup?
You primarily use the 'setStatus' action to release a number and the 'getStatus' to check verification status, combined with your logic to automate cleanup.
Can I automate number release if OTP is not received within the timeout?
Yes, you can set a timeout in your script and automatically release the number if no OTP arrives within that time to avoid unnecessary charges.
How do I handle failed or blocked numbers in automation scripts?
Detect failed or blocked statuses via API responses and trigger immediate release and optionally blacklist them in your system.
Is there example code for automating virtual number release?
SMSVerifier provides API documentation and sample scripts in curl, Python, and Node.js to automate number release and cleanup.
Does automating cleanup affect my account balance or refunds?
Releasing numbers promptly allows SMSVerifier to process refunds for unused numbers and helps maintain accurate account balance.

Ready to automate your virtual number release and cleanup?

Use SMSVerifier’s API to streamline your OTP verification workflows and save costs with prompt number release.

Read the API docs
Tags: api virtual-numbers automation otp sms-verification
Browse Services A-Z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z #
View all services →
From Our Blog
Browse all articles →