SDK Examples
Code examples for integrating with the SMS Gateway API using cURL, JavaScript, and Python. Each example shows a complete, working code snippet.
Base URL
All API requests should be made to the following base URL:
bash
1# Production2https://api.smsgateway.com34# Sandbox5https://api.smsgateway.comReplace sg_live_your_key with your actual API key. In sandbox, use sg_test_your_key.
Authentication
Include your API key in the Authorization header:
bash
1Authorization: Bearer sg_live_your_key_hereSend SMS
send-sms.sh
1curl -X POST https://api.smsgateway.com/api/v1/sms/send \2 -H "Authorization: Bearer sg_live_your_key_here" \3 -H "Content-Type: application/json" \4 -d '{5 "to": "+251911234567",6 "body": "Hello! Your verification code is 4829.",7 "from": "MyApp"8 }'Send Bulk SMS
send-bulk.sh
1curl -X POST https://api.smsgateway.com/api/v1/sms/bulk \2 -H "Authorization: Bearer sg_live_your_key_here" \3 -H "Content-Type: application/json" \4 -d '{5 "messages": [6 { "to": "+251911234567", "body": "Hello User 1!" },7 { "to": "+251911765432", "body": "Hello User 2!" },8 { "to": "+251911999888", "body": "Hello User 3!" }9 ],10 "from": "MyApp"11 }'Send OTP
send-otp.sh
1curl -X POST https://api.smsgateway.com/api/v1/otp/send \2 -H "Authorization: Bearer sg_live_your_key_here" \3 -H "Content-Type: application/json" \4 -d '{5 "to": "+251911234567",6 "length": 6,7 "expiresIn": 3008 }'Verify OTP
verify-otp.sh
1curl -X POST https://api.smsgateway.com/api/v1/otp/verify \2 -H "Authorization: Bearer sg_live_your_key_here" \3 -H "Content-Type: application/json" \4 -d '{5 "to": "+251911234567",6 "code": "482926"7 }'Check Delivery Status
check-status.sh
1curl -X GET https://api.smsgateway.com/api/v1/sms/msg_9x8y7z6w5v/status \2 -H "Authorization: Bearer sg_live_your_key_here"Create API Key
create-key.sh
1curl -X POST https://api.smsgateway.com/api/v1/developer/api-keys \2 -H "Authorization: Bearer <your_jwt_token>" \3 -H "Content-Type: application/json" \4 -d '{5 "name": "Production Server",6 "permissions": ["sms.send", "sms.read"],7 "expiresIn": "90d"8 }'Set Up Webhook
create-webhook.sh
1curl -X POST https://api.smsgateway.com/api/v1/developer/webhooks \2 -H "Authorization: Bearer <your_jwt_token>" \3 -H "Content-Type: application/json" \4 -d '{5 "name": "SMS Delivery Notifications",6 "url": "https://your-server.com/webhooks",7 "events": ["sms.delivered", "sms.failed"],8 "secret": "whsec_your_signing_secret"9 }'Error Handling
Always handle errors gracefully. Here are recommended patterns for each language:
error-handling.sh
1# Check HTTP status code2HTTP_CODE=$(curl -s -o response.json -w "%{http_code}" \3 -X POST https://api.smsgateway.com/api/v1/sms/send \4 -H "Authorization: Bearer sg_live_your_key_here" \5 -H "Content-Type: application/json" \6 -d '{"to": "+251911234567", "body": "Test"}')78if [ "$HTTP_CODE" -eq 429 ]; then9 echo "Rate limited! Check Retry-After header."10elif [ "$HTTP_CODE" -ge 400 ]; then11 echo "Error ($HTTP_CODE):"12 cat response.json13else14 echo "Success:"15 cat response.json16fi