Code examples
Send an SMS, read its status and check the balance in curl, Node, Python and PHP.
Set your key once. A jtsms_test_ key is the safe one to start with: nothing is sent and nothing is charged.
export JTSMS_API_KEY=jtsms_test_YOUR_KEYKeep keys in environment variables, not in code. Each sample prints the HTTP status and the JSON answer. Test for error.code on a failure: see Errors.
Send an SMS
curl -X POST "https://api.sms.jtnoble.com/v1/messages/send" \
-H "Authorization: Bearer $JTSMS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"to":"+2348030000000","text":"Your order 1042 is ready.","sender_id":"MYSHOP"}'const resp = await fetch('https://api.sms.jtnoble.com/v1/messages/send', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.JTSMS_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({"to":"+2348030000000","text":"Your order 1042 is ready.","sender_id":"MYSHOP"}),
});
console.log(resp.status, await resp.text());import os
import requests
resp = requests.post(
"https://api.sms.jtnoble.com/v1/messages/send",
headers={"Authorization": f"Bearer {os.environ['JTSMS_API_KEY']}"},
json={"to":"+2348030000000","text":"Your order 1042 is ready.","sender_id":"MYSHOP"},
timeout=30,
)
print(resp.status_code, resp.text)<?php
$ch = curl_init('https://api.sms.jtnoble.com/v1/messages/send');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('JTSMS_API_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"to":"+2348030000000","text":"Your order 1042 is ready.","sender_id":"MYSHOP"}',
]);
$body = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), ' ', $body, PHP_EOL;Read a message
Use the id from the send.
curl -X GET "https://api.sms.jtnoble.com/v1/messages/MESSAGE_ID" \
-H "Authorization: Bearer $JTSMS_API_KEY"const resp = await fetch('https://api.sms.jtnoble.com/v1/messages/MESSAGE_ID', {
method: 'GET',
headers: { Authorization: `Bearer ${process.env.JTSMS_API_KEY}` },
});
console.log(resp.status, await resp.text());import os
import requests
resp = requests.get(
"https://api.sms.jtnoble.com/v1/messages/MESSAGE_ID",
headers={"Authorization": f"Bearer {os.environ['JTSMS_API_KEY']}"},
timeout=30,
)
print(resp.status_code, resp.text)<?php
$ch = curl_init('https://api.sms.jtnoble.com/v1/messages/MESSAGE_ID');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('JTSMS_API_KEY')],
]);
$body = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), ' ', $body, PHP_EOL;Send to many numbers
curl -X POST "https://api.sms.jtnoble.com/v1/messages/send-bulk" \
-H "Authorization: Bearer $JTSMS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"recipients":[{"to":"+2348030001121","name":"Chinedu","vars":{"balance":"45,000"}},{"to":"+2348030001122","name":"Ada","vars":{"balance":"12,500"}}],"text":"Dear {first_name|parent}, your balance is USD {balance}."}'const resp = await fetch('https://api.sms.jtnoble.com/v1/messages/send-bulk', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.JTSMS_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({"recipients":[{"to":"+2348030001121","name":"Chinedu","vars":{"balance":"45,000"}},{"to":"+2348030001122","name":"Ada","vars":{"balance":"12,500"}}],"text":"Dear {first_name|parent}, your balance is USD {balance}."}),
});
console.log(resp.status, await resp.text());import os
import requests
resp = requests.post(
"https://api.sms.jtnoble.com/v1/messages/send-bulk",
headers={"Authorization": f"Bearer {os.environ['JTSMS_API_KEY']}"},
json={"recipients":[{"to":"+2348030001121","name":"Chinedu","vars":{"balance":"45,000"}},{"to":"+2348030001122","name":"Ada","vars":{"balance":"12,500"}}],"text":"Dear {first_name|parent}, your balance is USD {balance}."},
timeout=30,
)
print(resp.status_code, resp.text)<?php
$ch = curl_init('https://api.sms.jtnoble.com/v1/messages/send-bulk');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('JTSMS_API_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"recipients":[{"to":"+2348030001121","name":"Chinedu","vars":{"balance":"45,000"}},{"to":"+2348030001122","name":"Ada","vars":{"balance":"12,500"}}],"text":"Dear {first_name|parent}, your balance is USD {balance}."}',
]);
$body = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), ' ', $body, PHP_EOL;Send and check a code
curl -X POST "https://api.sms.jtnoble.com/v1/verify/start" \
-H "Authorization: Bearer $JTSMS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"to":"+2348030000000","app_name":"Shop"}'const resp = await fetch('https://api.sms.jtnoble.com/v1/verify/start', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.JTSMS_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({"to":"+2348030000000","app_name":"Shop"}),
});
console.log(resp.status, await resp.text());import os
import requests
resp = requests.post(
"https://api.sms.jtnoble.com/v1/verify/start",
headers={"Authorization": f"Bearer {os.environ['JTSMS_API_KEY']}"},
json={"to":"+2348030000000","app_name":"Shop"},
timeout=30,
)
print(resp.status_code, resp.text)<?php
$ch = curl_init('https://api.sms.jtnoble.com/v1/verify/start');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('JTSMS_API_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"to":"+2348030000000","app_name":"Shop"}',
]);
$body = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), ' ', $body, PHP_EOL;curl -X POST "https://api.sms.jtnoble.com/v1/verify/check" \
-H "Authorization: Bearer $JTSMS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"id":"vrf_8f2c0a6e1b7d4c3a9e5f1d20","code":"482913"}'const resp = await fetch('https://api.sms.jtnoble.com/v1/verify/check', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.JTSMS_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({"id":"vrf_8f2c0a6e1b7d4c3a9e5f1d20","code":"482913"}),
});
console.log(resp.status, await resp.text());import os
import requests
resp = requests.post(
"https://api.sms.jtnoble.com/v1/verify/check",
headers={"Authorization": f"Bearer {os.environ['JTSMS_API_KEY']}"},
json={"id":"vrf_8f2c0a6e1b7d4c3a9e5f1d20","code":"482913"},
timeout=30,
)
print(resp.status_code, resp.text)<?php
$ch = curl_init('https://api.sms.jtnoble.com/v1/verify/check');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('JTSMS_API_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"id":"vrf_8f2c0a6e1b7d4c3a9e5f1d20","code":"482913"}',
]);
$body = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), ' ', $body, PHP_EOL;Check your balance
curl -X GET "https://api.sms.jtnoble.com/v1/balance" \
-H "Authorization: Bearer $JTSMS_API_KEY"const resp = await fetch('https://api.sms.jtnoble.com/v1/balance', {
method: 'GET',
headers: { Authorization: `Bearer ${process.env.JTSMS_API_KEY}` },
});
console.log(resp.status, await resp.text());import os
import requests
resp = requests.get(
"https://api.sms.jtnoble.com/v1/balance",
headers={"Authorization": f"Bearer {os.environ['JTSMS_API_KEY']}"},
timeout=30,
)
print(resp.status_code, resp.text)<?php
$ch = curl_init('https://api.sms.jtnoble.com/v1/balance');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('JTSMS_API_KEY')],
]);
$body = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), ' ', $body, PHP_EOL;Every route has samples like these in the API reference.