Practical JavaScript / Node.js examples for the ASPSMS WebAPI (https://webapi.aspsms.com). Structure matches the WebAPI overview.
fetch) or modern browserasync function checkCredentials(userkey, password) {
const params = new URLSearchParams({ Userkey: userkey, Password: password });
const r = await fetch(`https://webapi.aspsms.com/CheckUserCredentials?${params}`);
return await r.json();
}
async function getCredits(userkey, password) {
const params = new URLSearchParams({ Userkey: userkey, Password: password });
const r = await fetch(`https://webapi.aspsms.com/ASPSMSCredits?${params}`);
return await r.json();
}
async function estimateCredits(userkey, password, msisdns) {
const params = new URLSearchParams({ Userkey: userkey, Password: password });
const r = await fetch(`https://webapi.aspsms.com/ASPSMSEstimateCreditConsumption?${params}`, {
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(msisdns)
});
return await r.json();
}
async function sendSimpleSms(userkey, password, msisdn, message, originator) {
const params = new URLSearchParams({
Userkey: userkey, Password: password, MSISDN: msisdn,
Operation: 'SendTextSMS', MessageData: message, Originator: originator
});
const r = await fetch(`https://webapi.aspsms.com/SendSimpleSMS?${params}`);
return await r.json();
}
async function sendAdvancedSms(userkey, password, message, originator, recipients) {
const params = new URLSearchParams({ Userkey: userkey, Password: password });
const payload = { Operation: 'SendTextSMS', Originator: originator, MessageData: message, Recipients: recipients };
const r = await fetch(`https://webapi.aspsms.com/ASPSMSSendSMS?${params}`, {
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload)
});
return await r.json();
}
Same originator for all, individual text (and optional TRN / deferred time) per recipient.
async function sendPersonalizedSms(userkey, password, originator, messages) {
// messages e.g.:
// [
// { PhoneNumber: '+41791111111', TransactionReferenceNumber: 'ORDER-1001',
// MessageData: 'Hi Anna, your order #1001 is on the way.' },
// { PhoneNumber: '+41792222222', TransactionReferenceNumber: 'ORDER-1002',
// MessageData: 'Hi Bruno, your order #1002 is on the way.',
// DeferredDeliveryTime: '2026-10-20T08:00:00' } // optional per recipient
// ]
const params = new URLSearchParams({ Userkey: userkey, Password: password });
const payload = {
Operation: 'SendTextSMS',
Originator: originator, // same for all
RecipientsEx: messages // individual MessageData per recipient
};
const r = await fetch(`https://webapi.aspsms.com/ASPSMSSendSMS?${params}`, {
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload)
});
return await r.json();
}
async function deactivateByMsisdn(userkey, password, msisdns) {
const params = new URLSearchParams({ Userkey: userkey, Password: password });
const r = await fetch(`https://webapi.aspsms.com/ASPSMSDeactivatePendingSMSWithMSISDN?${params}`, {
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(msisdns)
});
return await r.json();
}
<SCTS>, <DSCTS>, <RSN>, <DST>, <TRN>, <RCPNT>, <CREDITS> (max. 200 chars per URL).async function sendSmsWithWebhooks(userkey, password, message, originator, recipients) {
const params = new URLSearchParams({ Userkey: userkey, Password: password });
const payload = {
Operation: 'SendTextSMS', Originator: originator, MessageData: message, Recipients: recipients,
URLBufferedMessageNotification: 'https://your-domain.com/hook/buffered?SCTS=<SCTS>&DSCTS=<DSCTS>&RSN=<RSN>&DST=<DST>&TRN=<TRN>&RCPNT=<RCPNT>',
URLDeliveryNotification: 'https://your-domain.com/hook/delivered?SCTS=<SCTS>&DSCTS=<DSCTS>&RSN=<RSN>&DST=<DST>&TRN=<TRN>&RCPNT=<RCPNT>',
URLNonDeliveryNotification: 'https://your-domain.com/hook/failed?SCTS=<SCTS>&DSCTS=<DSCTS>&RSN=<RSN>&DST=<DST>&TRN=<TRN>&RCPNT=<RCPNT>'
};
const r = await fetch(`https://webapi.aspsms.com/ASPSMSSendSMS?${params}`, {
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload)
});
return await r.json();
}
| Value | Meaning |
|---|---|
| -1 | Not yet submitted / rejected |
| 0 | Delivered |
| 1 | Buffered |
| 2 | Not Delivered |
After status 1 (Buffered) you almost always get a second call with 0 or 2.
| Code | Meaning | Typical cause |
|---|---|---|
| 000 | Unknown Subscriber | Number does not exist |
| 103 | Call Barred | Blocked / empty prepaid |
| 107 | Absent Subscriber | Phone off / no network |
| 108 | Delivery Fail | Memory full or final failure |
| 110 | Protocol Error | Device problems |
| 118 | System fail | Severe network/device issues |
async function getTrafficStat(userkey, password, calculateCredits = true) {
const params = new URLSearchParams({ Userkey: userkey, Password: password, CalculateCredits: calculateCredits });
const r = await fetch(`https://webapi.aspsms.com/TrafficStat01/Get?${params}`);
return await r.json();
}
async function getSendingLog(userkey, password, year, month = 0, day = 0) {
const params = new URLSearchParams({ Userkey: userkey, Password: password, Year: year, Month: month, Day: day });
const r = await fetch(`https://webapi.aspsms.com/SendingStat01/Get?${params}`);
return await r.json();
}
async function getLogByTrn(userkey, password, trn) {
const params = new URLSearchParams({ Userkey: userkey, Password: password, TransactionReferenceNumber: trn });
const r = await fetch(`https://webapi.aspsms.com/SendingStat03/Get?${params}`);
return await r.json();
}
async function getLogByJob(userkey, password, jobId) {
const params = new URLSearchParams({ Userkey: userkey, Password: password, JobID: jobId });
const r = await fetch(`https://webapi.aspsms.com/SendingStat04/Get?${params}`);
return await r.json();
}
async function getReceivedSms(userkey, password, { year = 0, month = 0, day = 0, maxRecords = 100 } = {}) {
const params = new URLSearchParams({ Userkey: userkey, Password: password, Year: year, Month: month, Day: day, MaxRecords: maxRecords });
const r = await fetch(`https://webapi.aspsms.com/ReceivingStat01/Get?${params}`);
return await r.json();
}
async function setReceiveUrl(userkey, password, callbackUrl) {
const params = new URLSearchParams({ Userkey: userkey, Password: password, URL: callbackUrl });
const r = await fetch(`https://webapi.aspsms.com/ReceiveURL/Set?${params}`);
return await r.json();
}
async function getMsisdnDlrStat(userkey, password) {
const params = new URLSearchParams({ Userkey: userkey, Password: password });
const r = await fetch(`https://webapi.aspsms.com/MSISDNDLRStat/Get?${params}`);
return await r.json();
}
async function getPhonebook(userkey, password, msisdn = null) {
const params = new URLSearchParams({ Userkey: userkey, Password: password });
if (msisdn) params.append('MSISDN', msisdn);
const r = await fetch(`https://webapi.aspsms.com/PhoneNumbers/Read?${params}`);
return await r.json();
}
async function getGroups(userkey, password) {
const params = new URLSearchParams({ Userkey: userkey, Password: password });
const r = await fetch(`https://webapi.aspsms.com/Groups/Get?${params}`);
return await r.json();
}
async function getAllGroupRelations(userkey, password) {
const params = new URLSearchParams({ Userkey: userkey, Password: password });
const r = await fetch(`https://webapi.aspsms.com/GroupRelationsAll/Get?${params}`);
return await r.json();
}
Document sending actions. Pass JobID when sending; query messages later via SendingStat04.
async function getJobs(userkey, password) {
const params = new URLSearchParams({ Userkey: userkey, Password: password });
const r = await fetch(`https://webapi.aspsms.com/Jobs/Get?${params}`);
return await r.json();
}
async function getTemplates(userkey, password) {
const params = new URLSearchParams({ Userkey: userkey, Password: password });
const r = await fetch(`https://webapi.aspsms.com/Templates/Get?${params}`);
return await r.json();
}