Code Examples
Complete examples for integrating with the SMS API in popular programming languages.
cURL
Send SMS
curl -X POST https://kixon.app/api/send-sms \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"senderId": "MyBusiness",
"phone": "233200000000,233201111111",
"message": "Hello from our platform!"
}'Schedule SMS
curl -X POST https://kixon.app/api/scheduled-messages-direct \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"senderId": "MyBusiness",
"phone": "233200000000",
"message": "Reminder: Your appointment is tomorrow!",
"scheduledDate": "2026-04-10",
"scheduledTime": "10:00"
}
]
}'JavaScript (Node.js)
Using Fetch
const API_KEY = "YOUR_API_KEY";
const BASE_URL = "https://kixon.app/api";
async function sendSMS(senderId, phone, message) {
const response = await fetch(`${BASE_URL}/send-sms`, {
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
senderId: senderId,
phone: phone,
message: message,
}),
});
const result = await response.json();
if (!response.ok) {
throw new Error(result.error);
}
return result;
}
// Usage
sendSMS("MyBusiness", "233200000000", "Hello!")
.then((result) => console.log("Sent:", result.messageId))
.catch((error) => console.error("Error:", error.message));Using Axios
const axios = require("axios");
const api = axios.create({
baseURL: "https://kixon.app/api",
headers: {
Authorization: `Bearer ${process.env.SMS_API_KEY}`,
"Content-Type": "application/json",
},
});
async function sendSMS(senderId, phone, message) {
try {
const response = await api.post("/send-sms", {
senderId: senderId,
phone: phone,
message: message,
});
return response.data;
} catch (error) {
throw new Error(error.response?.data?.error || error.message);
}
}
// Usage
sendSMS("MyBusiness", "233200000000", "Hello from Node.js!")
.then((result) => console.log("Message ID:", result.messageId))
.catch((error) => console.error("Failed:", error.message));Python
Using Requests
import requests
import os
API_KEY = os.environ.get('SMS_API_KEY')
BASE_URL = 'https://kixon.app/api'
def send_sms(senderId: str, phone: str, message: str) -> dict:
"""Send an SMS message to one or more phone numbers (comma-separated)."""
response = requests.post(
f'{BASE_URL}/send-sms',
headers={
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'
},
json={
'senderId': senderId,
'phone': phone,
'message': message
}
)
result = response.json()
if not response.ok:
raise Exception(result.get('error', 'Unknown error'))
return result
def schedule_sms(messages: list) -> dict:
"""Schedule an SMS for future delivery."""
response = requests.post(
f'{BASE_URL}/scheduled-messages-direct',
headers={
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'
},
json={
'messages': messages
}
)
result = response.json()
if not response.ok:
raise Exception(result.get('error', 'Unknown error'))
return result
# Usage
if __name__ == '__main__':
try:
result = send_sms(
senderId='MyBusiness',
phone='233200000000',
message='Hello from Python!'
)
print(f"Sent! Message ID: {result['messageId']}")
except Exception as e:
print(f"Failed: {e}")PHP
<?php
class SMSClient {
private string $apiKey;
private string $baseUrl = 'https://kixon.app/api';
public function __construct(string $apiKey) {
$this->apiKey = $apiKey;
}
public function sendSMS(string $senderId, string $phone, string $message): array {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $this->baseUrl . '/send-sms',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $this->apiKey,
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => json_encode([
'senderId' => $senderId,
'phone' => $phone,
'message' => $message
])
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($response, true);
if ($httpCode !== 200) {
throw new Exception($result['error'] ?? 'Unknown error');
}
return $result;
}
}
// Usage
$client = new SMSClient('YOUR_API_KEY');
try {
$result = $client->sendSMS(
'MyBusiness',
'233200000000',
'Hello from PHP!'
);
echo "Sent! Message ID: " . $result['messageId'];
} catch (Exception $e) {
echo "Failed: " . $e->getMessage();
}Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
const baseURL = "https://kixon.app/api"
type SMSRequest struct {
SenderID string `json:"senderId"`
Phone string `json:"phone"`
Message string `json:"message"`
}
type SMSResponse struct {
Success bool `json:"success"`
MessageID string `json:"messageId"`
Error string `json:"error,omitempty"`
}
func sendSMS(apiKey string, req SMSRequest) (*SMSResponse, error) {
body, err := json.Marshal(req)
if err != nil {
return nil, err
}
httpReq, err := http.NewRequest("POST", baseURL+"/send-sms", bytes.NewBuffer(body))
if err != nil {
return nil, err
}
httpReq.Header.Set("Authorization", "Bearer "+apiKey)
httpReq.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(httpReq)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var result SMSResponse
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return nil, err
}
if !result.Success {
return nil, fmt.Errorf(result.Error)
}
return &result, nil
}
func main() {
apiKey := os.Getenv("SMS_API_KEY")
result, err := sendSMS(apiKey, SMSRequest{
SenderID: "MyBusiness",
Phone: "233200000000,233201111111",
Message: "Hello from Go!",
})
if err != nil {
fmt.Println("Failed:", err)
return
}
fmt.Println("Sent! Message ID:", result.MessageID)
}Ruby
require 'net/http'
require 'json'
require 'uri'
class SMSClient
BASE_URL = 'https://kixon.app/api'
def initialize(api_key)
@api_key = api_key
end
def send_sms(senderId:, phone:, message:)
uri = URI("#{BASE_URL}/send-sms")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Authorization'] = "Bearer #{@api_key}"
request['Content-Type'] = 'application/json'
request.body = {
senderId: senderId,
phone: phone,
message: message
}.to_json
response = http.request(request)
result = JSON.parse(response.body)
unless response.is_a?(Net::HTTPSuccess)
raise StandardError, result['error'] || 'Unknown error'
end
result
end
end
# Usage
client = SMSClient.new(ENV['SMS_API_KEY'])
begin
result = client.send_sms(
senderId: 'MyBusiness',
phone: '233200000000,233201111111',
message: 'Hello from Ruby!'
)
puts "Sent! Message ID: #{result['messageId']}"
rescue StandardError => e
puts "Failed: #{e.message}"
end