js-ubill
A JavaScript/TypeScript client for the Ubill API that simplifies SMS messaging operations.
npm install js-ubill
- Send SMS messages through the Ubill API
- Retrieve brand names
- Check account balance
- TypeScript support with full type definitions
import { UbillAPI } from "js-ubill";
const ubill = new UbillAPI({
apiKey: "your-api-key",
// Optional: override the default base URL
// baseUrl: 'https://custom-api-endpoint.com/v1'
});
async function sendMessage() {
try {
const response = await ubill.sendSMS({
brandID: 1,
numbers: [99555555555, 995555444111],
message: "Hello from Ubill!",
stopList: false, // optional: stopList flag
});
console.log("Message sent:", response);
} catch (error) {
console.error("Failed to send message:", error);
}
}
async function getBrands() {
try {
const response = await ubill.getAllBrandNames();
console.log("Available brands:", response.brands);
} catch (error) {
console.error("Failed to get brands:", error);
}
}
async function getBrand(brandId) {
try {
const brand = await ubill.getBrandName(brandId);
if (brand) {
console.log("Brand details:", brand);
} else {
console.log("Brand not found");
}
} catch (error) {
console.error("Failed to get brand:", error);
}
}
async function checkBalance() {
try {
const balance = await ubill.getBalance();
console.log("Current SMS balance:", balance.sms);
} catch (error) {
console.error("Failed to get balance:", error);
}
}
new UbillAPI(options: UbillAPIOptions)
- options.apiKey (required): Your Ubill API key
- options.baseUrl (optional): Custom API base URL (defaults to "https://api.ubill.dev/v1")
sendSMS(request: SendSMSRequest): Promise<SendSMSResponse>
Sends an SMS message to one or more recipients.
getAllBrandNames(): Promise<BrandNameResponse>
Retrieves all available brand names.
getBrandName(id: string): Promise<BrandName | null>
Retrieves a specific brand name by ID.
getBalance(): Promise<BalanceResponse>
Retrieves the current account balance.