การส่ง
ส่ง SMS จำนวนมากด้วย POST /v1/batches
/v1/batchesส่งถึงหมายเลขสูงสุด 10,000 หมายเลขในหนึ่งคำขอ ต้นทุนทั้งหมดจะถูกหักจากยอดเงินทันที
เนื้อหาคำขอ
- toarray of stringsไม่จำเป็น
หมายเลขสำหรับข้อความร่วมหนึ่งฉบับ ใช้ to กับ text หรือ messages
- textstringไม่จำเป็น
ข้อความร่วม จำเป็นเมื่อใช้ to
- messagesarray of objectsไม่จำเป็น
หนึ่ง {to, text} ต่อผู้รับ สำหรับข้อความส่วนตัว
- namestringไม่จำเป็น
ป้ายกำกับสำหรับคอนโซล สูงสุด 100 ตัวอักษร
- referencestringไม่จำเป็น
id ของคุณเอง สูงสุด 100 ตัวอักษร ส่งคืนในแบทช์และทุกข้อความ
- send_atstringไม่จำเป็น
เวลา ISO 8601 ล่วงหน้า 2 นาทีถึง 45 วัน
curl https://bulksmsapi.cc/v1/batches \
-H "Authorization: Bearer $BULKSMSAPI_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: spring-sale-0412" \
-d '{
"name": "Spring sale",
"text": "Spring sale at Northwind: 20% off until Sunday. Opt out: northwind.example/sms",
"to": [
"+14155550123",
"+447400123456",
"+4915123456789"
]
}'const res = await fetch("https://bulksmsapi.cc/v1/batches", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.BULKSMSAPI_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "spring-sale-0412",
},
body: JSON.stringify({
name: "Spring sale",
text: "Spring sale at Northwind: 20% off until Sunday. Opt out: northwind.example/sms",
to: ["+14155550123", "+447400123456", "+4915123456789"],
}),
});
const batch = await res.json();
console.log(res.status, batch.id, batch.recipients, batch.cost);import json, os, urllib.request
req = urllib.request.Request(
"https://bulksmsapi.cc/v1/batches",
data=json.dumps({
"name": "Spring sale",
"text": "Spring sale at Northwind: 20% off until Sunday. Opt out: northwind.example/sms",
"to": ["+14155550123", "+447400123456", "+4915123456789"],
}).encode(),
headers={
"Authorization": "Bearer " + os.environ["BULKSMSAPI_KEY"],
"Content-Type": "application/json",
"Idempotency-Key": "spring-sale-0412",
"User-Agent": "northwind-app/1.0",
},
method="POST",
)
with urllib.request.urlopen(req) as res:
batch = json.load(res)
print(res.status, batch["id"], batch["recipients"], batch["cost"])<?php
$ch = curl_init("https://bulksmsapi.cc/v1/batches");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("BULKSMSAPI_KEY"),
"Content-Type: application/json",
"Idempotency-Key: spring-sale-0412",
],
CURLOPT_POSTFIELDS => json_encode([
"name" => "Spring sale",
"text" => "Spring sale at Northwind: 20% off until Sunday. Opt out: northwind.example/sms",
"to" => ["+14155550123", "+447400123456", "+4915123456789"],
]),
]);
$batch = json_decode(curl_exec($ch), true);
echo $batch["id"], " ", $batch["recipients"], " ", $batch["cost"], "\n";package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
body, _ := json.Marshal(map[string]any{
"name": "Spring sale",
"text": "Spring sale at Northwind: 20% off until Sunday. Opt out: northwind.example/sms",
"to": []string{"+14155550123", "+447400123456", "+4915123456789"},
})
req, _ := http.NewRequest("POST", "https://bulksmsapi.cc/v1/batches", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("BULKSMSAPI_KEY"))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", "spring-sale-0412")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
var batch map[string]any
json.NewDecoder(res.Body).Decode(&batch)
fmt.Println(res.StatusCode, batch["id"], batch["recipients"], batch["cost"])
}{
"id": "bat_6TQ2W8M1ZK4N",
"object": "batch",
"name": "Spring sale",
"status": "queued",
"source": "api",
"encoding": "GSM-7",
"recipients": 3,
"max_segments": 1,
"cost": "0.02741",
"refunded": "0.00000",
"currency": "USD",
"counts": { "scheduled": 0, "queued": 3, "sent": 0, "delivered": 0, "failed": 0, "canceled": 0 },
"send_at": null,
"reference": null,
"created_at": "2026-11-07T09:31:40.102Z",
"completed_at": null,
"set_aside": []
}หมายเลขที่ถูกกันไว้
แต่ละหมายเลขจะถูกทำความสะอาดและคิดราคาแยกกัน หมายเลขที่ไม่สามารถส่งได้จะถูกแยกออกจากแบทช์ ไม่ถูกคิดเงิน และระบุใน set_aside พร้อมเหตุผล:
| reason | ความหมาย |
|---|---|
| invalid_number | ไม่สามารถอ่านเป็น + และตัวเลข 7 ถึง 15 หลักหลังทำความสะอาด |
| duplicate | หมายเลขเดียวกันปรากฏก่อนหน้าในคำขอ |
| unsupported_country | หมายเลขไม่อยู่ในประเทศที่คิดราคา |
| too_long | ข้อความส่วนตัวของมันต้องการมากกว่า 10 segments |
| empty_text | ข้อความส่วนตัวของมันว่างเปล่า |
| suppressed | หมายเลขอยู่ในรายชื่อไม่ส่งของคุณ |
หากไม่มีหมายเลขเหลือ คำขอจะล้มเหลวด้วยรหัสของเหตุผลแรก (เช่น invalid_number) และไม่มีการคิดเงิน
ข้อความส่วนตัวต่อหมายเลข
ใช้ messages เพื่อให้ข้อความส่วนตัวแก่ผู้รับแต่ละราย: ชื่อ เวลา จำนวนเงิน แต่ละข้อความจะถูกนับและคิดราคาแยกกัน ดังนั้นแบทช์สามารถผสมข้อความหนึ่ง segment และสอง segments
curl https://bulksmsapi.cc/v1/batches \
-H "Authorization: Bearer $BULKSMSAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Appointment reminders, 14 May",
"send_at": "2026-05-13T16:00:00Z",
"messages": [
{ "to": "+14155550123", "text": "Hi Ana, your dental check-up is tomorrow at 09:30." },
{ "to": "+14155550178", "text": "Hi Sam, your dental check-up is tomorrow at 11:00." }
]
}'การกำหนดเวลา
ด้วย send_at แบทช์และข้อความของมันจะรอในสถานะ scheduled และย้ายไปยังคิวในนาทีนั้น ต้นทุนจะถูกหักเมื่อคำขอได้รับการยอมรับ ดังนั้นแบทช์ที่กำหนดเวลาจะมีเงินทุนเสมอ แบทช์ที่กำหนดเวลาสามารถยกเลิกได้จนกว่าจะเริ่ม
/v1/batches/{id}/cancelยกเลิกแบทช์ที่กำหนดเวลา: ทุกข้อความจะถูกยกเลิกและต้นทุนเต็มจำนวนจะกลับคืนสู่ยอดเงินเป็นหนึ่งรายการคืนเงิน แบทช์ที่เริ่มแล้วจะตอบ 409 not_cancelable
curl -X POST https://bulksmsapi.cc/v1/batches/bat_6TQ2W8M1ZK4N/cancel \
-H "Authorization: Bearer $BULKSMSAPI_KEY"ดึงข้อมูลและแสดงรายการแบทช์
/v1/batches/{id}ชุดข้อความพร้อมจำนวนตามสถานะแบบเรียลไทม์ สามารถโพลเพื่อตรวจสอบความคืบหน้า หรือใช้เว็บฮุค
/v1/batchesชุดข้อความของบัญชี เรียงจากใหม่สุด พร้อมจำกัดจำนวน (1 ถึง 100) และ starting_after (รหัส bat_)
ฟิลด์ของชุดข้อความ
- idstring
bat_ ตามด้วยตัวอักษร 12 ตัว
- statusstring
scheduled, queued, sending, completed หรือ canceled
- sourcestring
api หรือ console
- encodingstring
GSM-7 หรือ UCS-2 เมื่อข้อความต้องการยูนิโค้ด
- recipientsinteger
หมายเลขที่รับเข้าในชุดข้อความ
- max_segmentsinteger
จำนวนส่วนที่มากที่สุดในข้อความ
- coststring
ยอดที่หักจากยอดเงิน, USD
- refundedstring
ยอดที่คืนแล้วสำหรับข้อความที่ล้มเหลวหรือยกเลิก
- countsobject
ข้อความตามสถานะ: scheduled, queued, sent, delivered, failed, canceled
- send_atstring or null
เวลาที่กำหนดส่ง (ถ้ามี)
- completed_atstring or null
เมื่อข้อความสุดท้ายถึงสถานะสุดท้าย
รายการขนาดใหญ่
แบ่งรายการที่มีมากกว่า 10,000 หมายเลขเป็นหลายคำขอ แต่ละคำขอมี Idempotency-Key ของตัวเอง (เช่น รหัสรายการและหมายเลขส่วน) ข้อความจะถูกส่งไปยังเครือข่ายตามลำดับสูงสุด 1,200 ข้อความต่อนาทีต่อบัญชี ดังนั้นแคมเปญ 50,000 หมายเลขจะถูกส่งภายในไม่ถึงหนึ่งชั่วโมง คอนโซลรับได้ 50,000 หมายเลขต่อแคมเปญจากการวางหรือไฟล์ CSV