JavaScript SDK
The galatext-api package supports SMS, credit purchases, sender IDs, campaigns, USSD, airtime, and WhatsApp. Version 1.3.0 introduces the bearer-token service methods below; older API-key SMS and account methods remain available.
Install
npm install galatext-apiUse Node.js 18 or later, or a browser providing fetch, AbortController, FormData, and Blob. Keep API keys in server code. Browser bundles do not protect embedded secrets.
The 1.3.0 changes in this workspace must be built and published before they are available through the package registry. To test the local checkout, run npm ci, npm test, and npm pack in galatext-api-js, then install the generated tarball in your application.
Configure credentials
import Galatext, { GalatextError } from 'galatext-api';
const client = new Galatext(process.env.GALATEXT_API_KEY, {
accessToken: process.env.GALATEXT_ACCESS_TOKEN,
baseURL: 'https://api.galatext.com/api',
timeout: 30000,
});Provide only an API key when using developer SMS and account endpoints. For bearer-only services, use new Galatext(null, { accessToken }). Obtain the token through /api/auth/login; see authentication. Update a renewed token with client.setAccessToken(newAccessToken).
The SDK sends only the credential required by the selected method. It does not log in, refresh tokens, or retry requests automatically. For local development, use baseURL: 'http://localhost:3030/api'.
CommonJS
const { Galatext } = require('galatext-api');Browser bundle
After the updated release is published:
<script src="https://unpkg.com/galatext-api@1.3.0/dist/galatext.umd.min.js"></script>
<script>
const client = new Galatext.Galatext(null, { accessToken: sessionAccessToken });
</script>Methods
| Namespace | Methods | Credential |
|---|---|---|
sms | send(phone, message, senderId?, options?), bulk(recipients, message, senderId?, options?), list(skip?, take?) | API key |
account | balance(), purchases(), buyCredits(product, quantity?, amount?, callbackUrl?), verifyPayment(reference) | API key |
senderIds | list(), request(body, options?) | API key |
senderIds | downloadForm() returning a Blob | Bearer token |
campaigns | create(body), list(query?), stats(), get(id), update(id, body), send(id), cancel(id), delete(id) | Bearer token |
ussd | create(body), list(query?), stats(), get(id), saveMenu(id, version, menu), publish(id, version), preview(id, text?, menu?), sessions(id, query?) | Bearer token |
airtime | networks(), balance(), purchase(body), transactions() | Bearer token |
whatsapp | configuration(), templates(), audience(recipients), send(body), logs(limit?), batch(id) | Bearer token |
Examples
SMS
const result = await client.sms.bulk(
['254712345678', '254798765432'],
'Our office will be closed on Monday.',
'YOURBRAND',
);
if (!result.success) console.error(result.error, result.totalFailed);Draft campaign
const draft = await client.campaigns.create({
name: 'Office notice',
message: 'Our office will be closed on Monday.',
senderId: 'YOURBRAND',
manualNumbers: ['254712345678'],
saveAsDraft: true,
requestId: crypto.randomUUID(),
});
const report = await client.campaigns.get(draft.id);Creation without saveAsDraft or a future scheduledAt queues an immediate send. Reuse requestId only for an identical creation payload.
USSD
const services = await client.ussd.list({ page: 1, limit: 10 });
const service = await client.ussd.get(serviceId);
const preview = await client.ussd.preview(service.id, '1');
const sessions = await client.ussd.sessions(service.id, { limit: 20 });Preview evaluates the saved draft without live sessions or charges. See the USSD guide for requesting a code, menu structure, and save/publish versions.
Airtime
const networks = await client.airtime.networks();
const result = await client.airtime.purchase({
network: 'safaricom',
recipients: [{ recipient: '254712345678', amount: 100 }],
});This sends actual airtime. Funding the balance through account.buyCredits('airtime', null, amount) is a separate operation.
Responses and errors
The SDK returns successful HTTP response bodies unchanged. Check success and sending counts for SMS, and inspect service-specific results. HTTP errors throw GalatextError with status, code, and message; validation arrays are joined into a readable message.
Direct SMS and airtime do not accept retry-safe client IDs. Review history after a timeout before repeating them. See errors for handling and retry guidance.