API Documentation
Complete reference for integrating with Twilio Service Center API
Overview
The Twilio Service Center API allows you to send SMS messages through our relay server. All requests must be authenticated using an API key.
Base URL
http://localhost:8000/relay/
Authentication
All API requests require authentication via the X-Proxy-Auth header.
X-Proxy-Auth: your_api_key_here
Important
Keep your API keys secure. Never expose them in client-side code or public repositories.
Send SMS
POST
/relay/sms
Send an SMS message through the relay server.
Request Headers
| Header | Type | Description |
|---|---|---|
X-Proxy-Auth |
string | Your API key |
Content-Type |
string | application/json |
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
To |
string | Yes | Recipient phone number (E.164 format) |
From |
string | No | Sender phone number |
Body |
string | Yes | Message content |
Example Request
curl -X POST http://localhost:8000/relay/sms \
-H "X-Proxy-Auth: your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"To": "+1234567890",
"From": "+0987654321",
"Body": "Hello from Twilio Service Center!"
}'
Success Response (200 OK)
{
"sid": "SM1234567890abcdef",
"status": "queued",
"cost": "0.0075",
"remaining_balance": "99.9925"
}
Webhooks
POST
/relay/twilio/webhook
Receives status callbacks from Twilio for message delivery updates.
Webhook Events
- queued - Message queued for delivery
- sent - Message sent to carrier
- delivered - Message delivered to recipient
- failed - Message delivery failed
Error Codes
| Code | Status | Description |
|---|---|---|
400 |
Bad Request | Missing required parameters (To or Body) |
401 |
Unauthorized | Invalid or missing API key |
402 |
Payment Required | Insufficient account balance |
500 |
Internal Server Error | No routing rule found or Twilio error |
Code Examples
Python
import requests
url = "http://localhost:8000/relay/sms"
headers = {
"X-Proxy-Auth": "your_api_key",
"Content-Type": "application/json"
}
data = {
"To": "+1234567890",
"Body": "Hello World"
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
JavaScript (Node.js)
const axios = require('axios');
const response = await axios.post(
'http://localhost:8000/relay/sms',
{
To: '+1234567890',
Body: 'Hello World'
},
{
headers: {
'X-Proxy-Auth': 'your_api_key',
'Content-Type': 'application/json'
}
}
);
console.log(response.data);