Invio
Invia un SMS con POST /v1/messages
/v1/messagesInvia un testo a un numero. Il costo viene prelevato dal saldo quando la richiesta è accettata.
Corpo della richiesta
- tostringobbligatorio
Il numero in formato internazionale, ad esempio +14155550123. Spazi, trattini, parentesi e il prefisso 00 vengono rimossi.
- textstringobbligatorio
Il messaggio. Fino a 10 segmenti; vedi Testo e segmenti.
- referencestringopzionale
Il tuo ID, fino a 100 caratteri. Viene restituito nell'oggetto messaggio e in ogni webhook.
- send_atstringopzionale
Orario ISO 8601 per l'invio, da 2 minuti a 45 giorni nel futuro. Senza, il messaggio viene accodato immediatamente.
Aggiungi un header Idempotency-Key per rendere i tentativi sicuri: vedi Idempotenza.
curl https://bulksmsapi.cc/v1/messages \
-H "Authorization: Bearer $BULKSMSAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "+14155550123",
"text": "Your Northwind code is 482913. It expires in 10 minutes.",
"reference": "login-7781"
}'// Node.js 18 or newer (built-in fetch)
const res = await fetch("https://bulksmsapi.cc/v1/messages", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.BULKSMSAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
to: "+14155550123",
text: "Your Northwind code is 482913. It expires in 10 minutes.",
reference: "login-7781",
}),
});
const message = await res.json();
console.log(res.status, message.id, message.status, message.price);# Python 3, standard library only
import json, os, urllib.request
req = urllib.request.Request(
"https://bulksmsapi.cc/v1/messages",
data=json.dumps({
"to": "+14155550123",
"text": "Your Northwind code is 482913. It expires in 10 minutes.",
"reference": "login-7781",
}).encode(),
headers={
"Authorization": "Bearer " + os.environ["BULKSMSAPI_KEY"],
"Content-Type": "application/json",
"User-Agent": "northwind-app/1.0",
},
method="POST",
)
with urllib.request.urlopen(req) as res:
message = json.load(res)
print(res.status, message["id"], message["status"], message["price"])<?php
// PHP 7.4 or newer with the curl extension
$ch = curl_init("https://bulksmsapi.cc/v1/messages");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("BULKSMSAPI_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"to" => "+14155550123",
"text" => "Your Northwind code is 482913. It expires in 10 minutes.",
"reference" => "login-7781",
]),
]);
$message = json_decode(curl_exec($ch), true);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), " ", $message["id"], " ", $message["status"], "\n";// Go 1.20 or newer, standard library only
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
body, _ := json.Marshal(map[string]any{
"to": "+14155550123",
"text": "Your Northwind code is 482913. It expires in 10 minutes.",
"reference": "login-7781",
})
req, _ := http.NewRequest("POST", "https://bulksmsapi.cc/v1/messages", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("BULKSMSAPI_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
var message map[string]any
json.NewDecoder(res.Body).Decode(&message)
fmt.Println(res.StatusCode, message["id"], message["status"], message["price"])
}{
"id": "msg_8F3K2Q9TZ1MX",
"object": "message",
"batch_id": "bat_4M7Q1X0PK2RS",
"to": "+14155550123",
"country": "US",
"text": "Your Northwind code is 482913. It expires in 10 minutes.",
"segments": 1,
"price": "0.00507",
"currency": "USD",
"status": "queued",
"error": null,
"reference": "login-7781",
"created_at": "2026-11-07T09:30:12.418Z",
"sent_at": null,
"done_at": null
}L'oggetto messaggio
Campi
- idstring
ID messaggio, msg_ seguito da 12 caratteri.
- objectstring
Sempre message.
- batch_idstring
Il batch a cui appartiene il messaggio (anche un singolo messaggio ottiene un batch).
- tostring
Il numero in formato E.164, dopo la pulizia.
- countrystring
Codice ISO 3166 del paese a cui è stato attribuito il prezzo del numero.
- textstring
Il testo come inviato, con i campi di merge compilati.
- segmentsinteger
Numero di segmenti SMS utilizzati dal testo.
- pricestring
Prezzo del messaggio in USD, 5 decimali (prezzo per segmento moltiplicato per i segmenti).
- currencystring
Sempre USD.
- statusstring
scheduled, queued, sent, delivered, failed o canceled.
- errorobject or null
Per messaggi failed o canceled: codice e messaggio.
- referencestring or null
Il tuo riferimento dalla richiesta.
- created_atstring
Quando la richiesta è stata accettata (ISO 8601, UTC).
- sent_atstring or null
Quando il messaggio è stato consegnato alla rete.
- done_atstring or null
Quando lo stato finale (delivered, failed o canceled) è stato impostato.
Recupera un messaggio
/v1/messages/{id}Un messaggio tramite il suo ID msg_. I messaggi di altri account restituiscono 404.
curl https://bulksmsapi.cc/v1/messages/msg_8F3K2Q9TZ1MX \
-H "Authorization: Bearer $BULKSMSAPI_KEY"const res = await fetch("https://bulksmsapi.cc/v1/messages/msg_8F3K2Q9TZ1MX", {
headers: { Authorization: `Bearer ${process.env.BULKSMSAPI_KEY}` },
});
const message = await res.json();
console.log(message.status, message.error);import json, os, urllib.request
req = urllib.request.Request(
"https://bulksmsapi.cc/v1/messages/msg_8F3K2Q9TZ1MX",
headers={"Authorization": "Bearer " + os.environ["BULKSMSAPI_KEY"], "User-Agent": "northwind-app/1.0"},
)
with urllib.request.urlopen(req) as res:
message = json.load(res)
print(message["status"], message["error"])<?php
$ch = curl_init("https://bulksmsapi.cc/v1/messages/msg_8F3K2Q9TZ1MX");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("BULKSMSAPI_KEY")],
]);
$message = json_decode(curl_exec($ch), true);
echo $message["status"], "\n";package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
req, _ := http.NewRequest("GET", "https://bulksmsapi.cc/v1/messages/msg_8F3K2Q9TZ1MX", nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("BULKSMSAPI_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
var message map[string]any
json.NewDecoder(res.Body).Decode(&message)
fmt.Println(message["status"], message["error"])
}Lista messaggi
/v1/messagesMessaggi dell'account, dal più recente.
Parametri di query
- batch_idstringopzionale
Solo i messaggi di questo batch bat_.
- statusstringopzionale
scheduled, queued, sent, delivered, failed o canceled.
- limitintegeropzionale
Da 1 a 100, predefinito 20.
- starting_afterstringopzionale
Un msg_ id: la pagina inizia dopo di esso. Usa l'ultimo id della pagina precedente.
curl "https://bulksmsapi.cc/v1/messages?status=failed&limit=50" \
-H "Authorization: Bearer $BULKSMSAPI_KEY"{
"object": "list",
"data": [ { "id": "msg_8F3K2Q9TZ1MX", "object": "message", "status": "failed", "...": "..." } ],
"has_more": false
}