How to Send Normal SMS
This action requires headers to be sent with your API Key. This can be retrieved from your account by accessing the api details section
You can send a single SMS to one or many recipients by making a HTTP POST request with the following:
Endpoint
https://service.textpie.co.ke/api/v1/customer/send_sms
Request Body
{
"callback_url": "https://mycallback.com/",
"sender_id": "textpie",
"api_username": "my_username",
"message_data": [
{
"recipient": "+2547xxx",
"message": "Hello Textpie!"
}
]
}
Code Examples
curl --location 'https://service.textpie.co.ke/api/v1/customer/send_sms' \
--header 'X-API-KEY: {API_KEY}' \
--header 'Content-Type: text/plain' \
--data '{
"callback_url": "{CALLBACK_URL}",
"sender_id": "{SENDER_ID}",
"api_username": "{API_USENAME}",
"message_data": [
{
"recipient": "+2547xxx",
"message": "Hello Textpie!"
}
]
}'
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "{\"callback_url\": \"{CALLBACK_URL}\", \"sender_id\": \"{SENDER_ID}\", \"api_username\": \"{API_USERNAME}\", \"message_data\": [{\"recipient\": \"+2547xxx\", \"message\": \"Hello Textpie!\"}");
Request request = new Request.Builder()
.url("https://service.textpie.co.ke/api/v1/customer/send_sms")
.method("POST", body)
.addHeader("X-API-KEY", "{API_KEY}")
.addHeader("Content-Type", "text/plain")
.build();
Response response = client.newCall(request).execute();
var http = require('follow-redirects').http;
var fs = require('fs');
var options = {
'method': 'POST',
'hostname': 'service.textpie.co.ke',
'path': '/api/v1/customer/send_sms',
'headers': {
'X-API-KEY': '{API_KEY}',
'Content-Type': 'text/plain'
},
'maxRedirects': 20
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = "{\"callback_url\": \"{CALLBACK_URL}\", \"sender_id\": \"{SENDER_ID}\", \"api_username\": \"{API_USERNAME}\", \"message_data\": [{\"recipient\": \"+2547xxx\", \"message\": \"Hello Textpie!\"}";
req.write(postData);
req.end();
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://service.textpie.co.ke/api/v1/customer/send_sms',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"callback_url": "{CALLBACK_URL}",
"sender_id": "{SENDER_ID}",
"api_username": "{API_USERNAME}",
"message_data": [
{
"recipient": "+2547xxx",
"message": "Hello Textpie!"
}
]
}',
CURLOPT_HTTPHEADER => array(
'X-API-KEY: {API_KEY}',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
url = "https://service.textpie.co.ke/api/v1/customer/send_sms"
payload = {
"callback_url": "{CALLBACK_URL}",
"sender_id": "{SENDER_ID}",
"api_username": "{API_USERNAME}",
"message_data": [
{
"recipient": "+2547xxx",
"message": "Hello Textpie"
}
]
}
headers = {
'X-API-KEY': '{API_KEY}',
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, json=payload)
print(response.text)
require "uri"
require "json"
require "net/http"
url = URI("https://service.textpie.co.ke/api/v1/customer/send_sms")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = "{API_KEY}"
request["Content-Type"] = "application/json"
request.body = {
:callback_url => "{CALLBACK_URL}",
:sender_id => "{SENDER_ID}",
:api_username => "{API_USERNAME}",
:message_data => [
{
:recipient => "+2547xxx",
:message => "Hello Textpie!"
}
]
}.to_json
response = https.request(request)
puts response.read_body
Payload
Parameter | Description | Required |
---|---|---|
callback_url | URL to receive delivery notifications for messages | YES |
sender_id | SMS Sender ID | YES |
api_username | Account username. This can be retrieved from your account's API details menu | YES |
message_data | List of messages to be send grouped by recipient and message, check the sample source code section for examples | YES |
Example of a Successful Response
{
"message": "string",
"recipients": [
{
"status_code": 0,
"phone_number": "string",
"status": "string",
"units": 0,
"message_id": "string"
}
]
}
Status codes
Code | Description |
---|---|
201 | SMS message(s) successfully queued |
400 | Authentication error |
401 | Authentication error |
402 | Insufficient units |
403 | Invalid sender id |
405 | Recipient limit error |