OTP: send a code
OTP: send a code #
POST /v1/otp/send
POST
/otp/send
Send a one-time verification code (OTP) to a phone number. Callisto generates the code and puts it in your message in place of {code}.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
to |
string | Yes | Recipient number, in international format |
message |
string | Yes | Your message. It must contain {code} (5-500 characters). |
sender |
string | No | Sender ID, approved on your account. Optional: without it, your organization's default, then the platform's (see sending an SMS). Ignored when the code goes out on WhatsApp. |
expired_in |
integer | Yes | How long the code stays valid, in seconds (60 - 86400) |
digit_size |
integer | No | Length of the code (4-16, default: 6) |
type |
string | No | Kind of code: digit, alpha or alphanumeric (default: digit). Letter codes are uppercase, and checking is case-sensitive. |
provider |
string | No | Channel that delivers the code: sms (default) or whatsapp |
instanceCode |
string | Conditional | Code of the WhatsApp instance to send from. Required when provider = whatsapp. |
Example request
// Envoyer un code OTP
const credentials = btoa('ACCESS_KEY:ACCESS_SECRET');
const res = await fetch('https://api.callistosignal.com/v1/otp/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + credentials
},
body: JSON.stringify({
to: '+22507XXXXXXXX',
message: 'Votre code de vérification est {code}',
sender: 'MyApp',
digit_size: 6,
expired_in: 300,
type: 'digit',
provider: 'sms'
})
});
if (!res.ok) {
// 400, 401, 429… : le corps porte le motif du refus
const { message } = await res.json();
throw new Error(`OTP refusé (${res.status}) : ${message}`);
}
const { id, recipient, expires_at } = await res.json();
// Envoyer un code OTP
$ch = curl_init('https://api.callistosignal.com/v1/otp/send');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_USERPWD => 'ACCESS_KEY:ACCESS_SECRET',
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'to' => '+22507XXXXXXXX',
'message' => 'Votre code de vérification est {code}',
'sender' => 'MyApp',
'digit_size' => 6,
'expired_in' => 300,
'type' => 'digit',
'provider' => 'sms',
]),
]);
$response = curl_exec($ch);
# Envoyer un code OTP (pip install requests)
import requests
res = requests.post(
'https://api.callistosignal.com/v1/otp/send',
auth=('ACCESS_KEY', 'ACCESS_SECRET'),
json={
'to': '+22507XXXXXXXX',
'message': 'Votre code de vérification est {code}',
'sender': 'MyApp',
'digit_size': 6,
'expired_in': 300,
'type': 'digit',
'provider': 'sms',
},
timeout=10,
)
if not res.ok:
# 400, 401, 429… : le corps porte le motif du refus
raise RuntimeError('OTP refusé (%d) : %s' % (res.status_code, res.json().get('message')))
otp = res.json() # id, recipient, expires_at
// Envoyer un code OTP
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
body, _ := json.Marshal(map[string]any{
"to": "+22507XXXXXXXX",
"message": "Votre code de vérification est {code}",
"sender": "MyApp",
"digit_size": 6,
"expired_in": 300,
"type": "digit",
"provider": "sms",
})
req, _ := http.NewRequest("POST", "https://api.callistosignal.com/v1/otp/send", bytes.NewReader(body))
req.SetBasicAuth("ACCESS_KEY", "ACCESS_SECRET")
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
var out map[string]any
json.NewDecoder(res.Body).Decode(&out)
if res.StatusCode >= 300 {
// 400, 401, 429… : le corps porte le motif du refus
panic(fmt.Sprintf("OTP refusé (%d) : %v", res.StatusCode, out["message"]))
}
fmt.Println(out["id"], out["expires_at"])
}
curl -u 'ACCESS_KEY:ACCESS_SECRET' \
-X POST https://api.callistosignal.com/v1/otp/send \
-H 'Content-Type: application/json' \
-d '{
"to": "+22507XXXXXXXX",
"message": "Votre code de vérification est {code}",
"sender": "MyApp",
"digit_size": 6,
"expired_in": 300,
"type": "digit",
"provider": "sms"
}'
Response
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"provider": "sms",
"recipient": "+22507XXXXXXXX",
"expires_at": "2026-04-07T10:35:00Z",
"expires_in": 300
}
Sending the code on WhatsApp
To send the code from one of your connected WhatsApp instances, add provider: "whatsapp" and instanceCode. The sender field is then ignored.
{
"to": "+22507XXXXXXXX",
"message": "Votre code Callisto est {code}",
"expired_in": 300,
"digit_size": 6,
"type": "digit",
"provider": "whatsapp",
"instanceCode": "{instanceCode}"
}
The response is the same, with "provider": "whatsapp". The API returns 400 if instanceCode is missing or the instance is not connected.
A code sent by SMS ("provider": "sms") costs 1 credit. Without it, the call answers 402: no code is created and nothing is charged.
{
"message": "Insufficient credits. Required: 1, Available: 0"
}
Note: Save the id from the response. You need it to verify the code.