← Back to Home

NEXSMS Messaging API

Developer guide for sending SMS messages through NEXSMS

🚀 Quick Start
Start sending SMS messages with NEXSMS in minutes

1. Get Your API Keys

Contact admin to create a client account and receive your API keys.

Base URL: https://your-nexsms-domain.com/api

2. Authentication

Include your API keys in the headers for all requests:

x-public-key: YOUR_PUBLIC_KEY
x-secret-key: YOUR_SECRET_KEY

3. Send Your First Message

Use the /api/messages/send endpoint to send SMS messages:

POST /api/messages/send
Content-Type: application/json
POSTSend SMS Message
/api/messages/send

Request Body:

{
  "to": "+1234567890",
  "body": "Hello from NEXSMS!",
  "deviceId": "optional-device-id"
}

Note: Phone numbers are not stored or managed server-side. Always provide the destination number in the to field for each request.

Response:

{
  "success": true,
  "messageId": "msg_123456789",
  "message": "Message queued for sending"
}

cURL Example:

curl -X POST https://your-domain.com/api/messages/send   -H "Content-Type: application/json"   -H "x-public-key: YOUR_PUBLIC_KEY"   -H "x-secret-key: YOUR_SECRET_KEY"   -d '{
    "to": "+1234567890",
    "body": "Hello from NEXSMS!"
  }'

The device processes queued messages and sends SMS using the providedto number; no phone number registry exists on the server.

Devices fetch queued messages via /api/device/messages/pending and report status (sent or failed) via /api/device/messages/[messageId]/status. A device is considered online if it has attempted a poll in the last 4 minutes. When no device is specified, the server selects an active device and prioritizes devices that are online.

GETGet Message Logs
/api/messages/logs

Query Parameters:

  • limit: Number of logs to retrieve (1-100, default: 20)

Response:

{
  "success": true,
  "logs": [
    {
      "id": "msg_123456789",
      "to": "+1234567890",
      "body": "Hello from NEXSMS!",
      "status": true,
      "sentAt": "2024-01-15T10:30:00Z",
      "deviceId": "device_abc123",
      "createdAt": "2024-01-15T10:29:45Z"
    }
  ],
  "count": 1
}
HTTP Status Codes

Success Codes

  • 200 - OK
  • 201 - Created

Error Codes

  • 400 - Bad Request
  • 401 - Unauthorized
  • 403 - Forbidden
  • 404 - Not Found
  • 429 - Rate Limited
  • 500 - Internal Server Error
Code Examples
Implementation examples in popular programming languages
// Send SMS using fetch API
const sendSMS = async (to, message) => {
  const response = await fetch('https://your-domain.com/api/messages/send', {
    method: 'POST',
    headers: {
      'X-Public-Key': 'YOUR_PUBLIC_KEY',
      'X-Secret-Key': 'YOUR_SECRET_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ to, message })
  });
  
  return await response.json();
};

// Usage
sendSMS('+1234567890', 'Hello from NEXSMS!')
  .then(result => console.log('Message sent:', result))
  .catch(error => console.error('Error:', error));