Autenticazione
Tutte le richieste richiedono l'header Authorization: Bearer tg_live_xxxxx. Le chiavi sono generate dal pannello (sezione API keys), sono permanenti finche non le revochi e possono avere scope (es. solo send, solo read).
Endpoint /v1/messages REST con autenticazione Bearer, idempotency key, rate limiting trasparente.
Tutte le richieste richiedono l'header Authorization: Bearer tg_live_xxxxx. Le chiavi sono generate dal pannello (sezione API keys), sono permanenti finche non le revochi e possono avere scope (es. solo send, solo read).
curl -X POST https://api.targetsmtp.it/v1/messages \
-H "Authorization: Bearer $TARGET_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"from": "noreply@tuosito.it",
"to": ["utente@example.com"],
"subject": "Conferma ordine #1024",
"html": "<p>Grazie!</p>",
"tags": ["order-confirmation"]
}'// PHP 8+ con HTTP client built-in via file_get_contents:
$payload = json_encode([
"from" => "noreply@tuosito.it",
"to" => ["utente@example.com"],
"subject" => "Conferma ordine #1024",
"html" => "<p>Grazie!</p>",
]);
$ctx = stream_context_create([
"http" => [
"method" => "POST",
"header" => [
"Authorization: Bearer " . $TARGET_KEY,
"Content-Type: application/json",
"Idempotency-Key: " . bin2hex(random_bytes(16)),
],
"content" => $payload,
],
]);
$resp = json_decode(file_get_contents("https://api.targetsmtp.it/v1/messages", false, $ctx), true);await fetch('https://api.targetsmtp.it/v1/messages', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.TARGET_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': crypto.randomUUID(),
},
body: JSON.stringify({
from: 'noreply@tuosito.it',
to: ['utente@example.com'],
subject: 'Conferma ordine #1024',
html: '<p>Grazie!</p>',
}),
});import os, uuid, requests
r = requests.post(
'https://api.targetsmtp.it/v1/messages',
headers={
'Authorization': f'Bearer {os.environ["TARGET_KEY"]}',
'Content-Type': 'application/json',
'Idempotency-Key': str(uuid.uuid4()),
},
json={
'from': 'noreply@tuosito.it',
'to': ['utente@example.com'],
'subject': 'Conferma ordine #1024',
'html': '<p>Grazie!</p>',
},
)
print(r.json())Passa un header Idempotency-Key (UUID v4 raccomandato): se ritenti la stessa richiesta in caso di timeout di rete, garantiamo che il messaggio non sia inviato due volte. La chiave e valida 24 ore.
Le risposte includono header X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset. Quando esaurito, riceverai HTTP 429 con Retry-After. Il limite per ora dipende dal piano (vedi pricing).
Tutti gli errori restituiscono JSON con error.code, error.message, e error.field dove utile. Status code HTTP semantici: 400 validazione, 401 auth, 402 quota esaurita, 422 dato non processabile, 429 rate limit, 5xx server.