ExampleUpdated 15 Oct 2026
Sending SMS through BulkSMS gateway from Docly JS API
This example sends an SMS from your Docly JS API through BulkSMS. It requires a BulkSMS account with credits. The endpoint only accepts POST from a signed-in user, and the BulkSMS credentials are read from #/Config — never put them in the code.
Example
Code #/API/SMS.js
// #/API/SendSms.js — POST { to, body } from a signed-in user.
export default (to, body) => {
// Sending costs money, so a link on another site must not be able to trigger it.
if (request.method != "POST") throw new Error("Verb not supported");
// Only signed-in users may send. Add your own role check here if not all of them should.
if (!request.user) return docly.denyAccess();
if (!to || !body) throw new Error("Missing recipient or message");
// Credentials live in #/Config (password fields), never in code.
let config = docly.getJson("#/Config") || {};
if (!config.BulkSmsUser || !config.BulkSmsPassword)
throw new Error("BulkSMS is not configured");
let data = {
"to": to, // e.g. "+4712345678"
"body": body,
"encoding": "UNICODE" // unicode recommended
// "from": "MyID" // sender ID, optional
};
let headers = {
"Authorization": "Basic " + docly.base64(config.BulkSmsUser + ":" + config.BulkSmsPassword)
};
let result = docly.httpPost("https://api.bulksms.com/v1/messages", data, headers);
if (result && result.DoclyError) throw new Error("Could not send the SMS");
return result;
}