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
- Log in to your dashboard and go to Numbers.
- Filter by Non-VoIP to display mobile numbers.
- Select country, quantity, and rental duration.
- Complete payment (e.g., $0.25 for 24h rental).
- Note the
number_id
for API calls.
Key Endpoints
Purpose | Method | Endpoint |
---|---|---|
List rented numbers | GET | /v1/numbers |
Poll messages | GET | /v1/numbers/{number_id}/messages |
Register webhook | POST | /v1/webhooks |
List webhooks | GET | /v1/webhooks |
Delete webhook | DELETE | /v1/webhooks/{webhook_id} |
Account details & balance | GET | /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)
- 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" }'
- Handle inbound POSTs at
/text2fa-webhook
:{ "number_id": "12345", "from": "+12135559876", "message": "Your OTP is 843291", "received_at": "2025-06-26T08:15:00Z" }
- 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: