Text2FA API Integration Guide

text2fa

text2fa

6/26/2025

Text2FA API Integration Guide

Prerequisites

  • A Text2FA account (sign up at https://text2fa.com)
  • At least one rented non-VoIP number in your dashboard
  • Your API key (Settings → API Key)
  • A development environment for your chosen language (Node.js, Python, PHP, etc.)

Authentication

Every request must include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Renting a Non-VoIP Number

  1. Log in to your dashboard and go to Numbers.
  2. Filter by Non-VoIP to display mobile numbers.
  3. Select country, quantity, and rental duration.
  4. Complete payment (e.g., $0.25 for 24h rental).
  5. Note the number_id for API calls.

Key Endpoints

PurposeMethodEndpoint
List rented numbersGET/v1/numbers
Poll messagesGET/v1/numbers/{number_id}/messages
Register webhookPOST/v1/webhooks
List webhooksGET/v1/webhooks
Delete webhookDELETE/v1/webhooks/{webhook_id}
Account details & balanceGET/v1/account-details

Listing Your Numbers

curl -X GET https://api.text2fa.com/v1/numbers \
     -H "Authorization: Bearer YOUR_API_KEY"

Response sample:

[
  {
    "id": "12345",
    "number": "+15551234567",
    "type": "non-voip",
    "country": "US"
  }
]

Receiving SMS Messages

A. Polling (Basic)

curl -X GET https://api.text2fa.com/v1/numbers/12345/messages \
     -H "Authorization: Bearer YOUR_API_KEY"

Response sample:

[
  {
    "from": "+12135559876",
    "message": "Your OTP is 843291",
    "received_at": "2025-06-26T08:15:00Z"
  }
]

B. Webhooks (Real-Time)

  1. Register your webhook: curl -X POST https://api.text2fa.com/v1/webhooks \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "url": "https://yourapp.com/text2fa-webhook" }'
  2. Handle inbound POSTs at /text2fa-webhook: { "number_id": "12345", "from": "+12135559876", "message": "Your OTP is 843291", "received_at": "2025-06-26T08:15:00Z" }
  3. Example handler (Node.js/Express): import express from 'express'; const app = express(); app.use(express.json()); app.post('/text2fa-webhook', (req, res) => { const { number_id, from, message, received_at } = req.body; console.log(`SMS for ${number_id} from ${from}: ${message}`); res.sendStatus(200); }); app.listen(3000, () => console.log('Listening on 3000'));

Code Examples

Python (requests)

import requests

API_KEY = "YOUR_API_KEY"
headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
}

# List numbers
resp = requests.get("https://api.text2fa.com/v1/numbers", headers=headers)
print(resp.json())

PHP (cURL)

<?php
$apiKey = 'YOUR_API_KEY';
$ch = curl_init('https://api.text2fa.com/v1/numbers');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer {$apiKey}",
    "Content-Type: application/json",
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$numbers = json_decode($response, true);
print_r($numbers);

Best Practices

  • Secure Webhooks: Validate requests using signatures or IP whitelisting.
  • Error Handling: Implement retries with exponential backoff on 5xx errors.
  • Rate Limits: Respect API limits; batch polling intervals.
  • Key Rotation: Periodically regenerate your API key in the dashboard.
  • Analytics: Monitor delivery rates in Analytics → Reports.

Conclusion

Rent a number, plug in your API key, and start processing SMS with Text2FA’s simple REST API. For complete details, visit:

🔗 https://text2fa.com/api-documentation