Autenticazione
Tutte le richieste API richiedono autenticazione tramite una delle seguenti modalità.
API Key (consigliata)
:::tip Metodo consigliato L'autenticazione tramite API Key è il metodo più semplice e sicuro. Non richiede la codifica Base64 e riduce il rischio di esporre le credenziali nei log. :::
Il metodo più semplice. Aggiungi l'header X-Api-Key a ogni richiesta:
- cURL
- Node.js
- Python
- PHP
curl -X POST "https://lora-api.agiletelecom.com/api/message-server/sms/send" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"destination": "+393401234567",
"sender": "MyCompany",
"body": "Hello world"
}'
const response = await fetch(
"https://lora-api.agiletelecom.com/api/message-server/sms/send",
{
method: "POST",
headers: {
"X-Api-Key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
destination: "+393401234567",
sender: "MyCompany",
body: "Hello world",
}),
}
);
const data = await response.json();
console.log(data);
import requests
response = requests.post(
"https://lora-api.agiletelecom.com/api/message-server/sms/send",
headers={
"X-Api-Key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
json={
"destination": "+393401234567",
"sender": "MyCompany",
"body": "Hello world",
},
)
print(response.json())
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://lora-api.agiletelecom.com/api/message-server/sms/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"X-Api-Key: YOUR_API_KEY",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"destination" => "+393401234567",
"sender" => "MyCompany",
"body" => "Hello world",
]),
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Non condividere mai la tua API Key in repository pubblici, codice client-side o canali non sicuri. Se compromessa, rigenerala immediatamente dalla piattaforma Qlara.
La tua API Key è disponibile nella sezione impostazioni della piattaforma Qlara.
Basic Auth
Metodo standard HTTP con username e password codificati in Base64:
- cURL
- Node.js
- Python
- PHP
curl -X POST "https://lora-api.agiletelecom.com/api/message-server/sms/send" \
-H "Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=" \
-H "Content-Type: application/json" \
-d '{
"destination": "+393401234567",
"sender": "MyCompany",
"body": "Hello world"
}'
const response = await fetch(
"https://lora-api.agiletelecom.com/api/message-server/sms/send",
{
method: "POST",
headers: {
Authorization: "Basic " + btoa("username:password"),
"Content-Type": "application/json",
},
body: JSON.stringify({
destination: "+393401234567",
sender: "MyCompany",
body: "Hello world",
}),
}
);
const data = await response.json();
console.log(data);
import requests
response = requests.post(
"https://lora-api.agiletelecom.com/api/message-server/sms/send",
auth=("username", "password"),
headers={
"Content-Type": "application/json",
},
json={
"destination": "+393401234567",
"sender": "MyCompany",
"body": "Hello world",
},
)
print(response.json())
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://lora-api.agiletelecom.com/api/message-server/sms/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_USERPWD => "username:password",
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"destination" => "+393401234567",
"sender" => "MyCompany",
"body" => "Hello world",
]),
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Come generare il valore Base64
Linux / macOS:
echo -n "username:password" | base64
Windows PowerShell:
[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("username:password"))
IP Whitelist
Per ogni account può essere configurata una lista di IP abilitati nella piattaforma Qlara. Se attiva, richieste da IP non autorizzati ricevono 403 Forbidden.
Errori di autenticazione
| Codice | Significato | Cosa fare |
|---|---|---|
401 | Credenziali mancanti o non valide | Verifica la tua API Key o le credenziali Basic |
403 | IP non autorizzato o risorsa non accessibile | Verifica la whitelist IP nella piattaforma |