Tài khoản
Số dư và ước tính chi phí
GET
/v1/balanceSố dư hiện tại bằng USD.
curl https://bulksmsapi.cc/v1/balance \
-H "Authorization: Bearer $BULKSMSAPI_KEY"const res = await fetch("https://bulksmsapi.cc/v1/balance", {
headers: { Authorization: `Bearer ${process.env.BULKSMSAPI_KEY}` },
});
const { balance, currency } = await res.json();
console.log(balance, currency);import json, os, urllib.request
req = urllib.request.Request(
"https://bulksmsapi.cc/v1/balance",
headers={"Authorization": "Bearer " + os.environ["BULKSMSAPI_KEY"], "User-Agent": "northwind-app/1.0"},
)
with urllib.request.urlopen(req) as res:
print(json.load(res)["balance"])<?php
$ch = curl_init("https://bulksmsapi.cc/v1/balance");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("BULKSMSAPI_KEY")],
]);
echo json_decode(curl_exec($ch), true)["balance"], "\n";package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
req, _ := http.NewRequest("GET", "https://bulksmsapi.cc/v1/balance", 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 b struct{ Balance, Currency string }
json.NewDecoder(res.Body).Decode(&b)
fmt.Println(b.Balance, b.Currency)
}{
"object": "balance",
"balance": "184.32950",
"currency": "USD"
}Ước tính
POST
/v1/estimatesLấy cùng một body như POST /v1/batches và trả về chi phí sẽ phải trả. Không có gì được gửi và không có gì được tính phí.
curl https://bulksmsapi.cc/v1/estimates \
-H "Authorization: Bearer $BULKSMSAPI_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Doors open at 18:00 tonight.", "to": ["+14155550123", "+447400123456", "+447400123456", "12"]}'{
"object": "estimate",
"recipients": 2,
"set_aside": [
{ "to": "+447400123456", "reason": "duplicate" },
{ "to": "12", "reason": "invalid_number" }
],
"encoding": "GSM-7",
"segments": 2,
"max_segments": 1,
"cost": "0.01294",
"currency": "USD",
"by_country": [
{ "country": "US", "recipients": 1, "segments": 1, "cost": "0.00507" },
{ "country": "GB", "recipients": 1, "segments": 1, "cost": "0.00787" }
]
}Sắp hết
Một yêu cầu có chi phí cao hơn số dư sẽ trả lời 402 top_up_required với cả hai số tiền trong tin nhắn, và không có gì được gửi. Kiểm tra số dư trước khi thực hiện một batch lớn, hoặc ước tính trước, và nạp tiền trong console.