ASPSMS WebAPI – JavaScript / Node.js Code Examples

Practical JavaScript / Node.js examples for the ASPSMS WebAPI (https://webapi.aspsms.com). Structure matches the WebAPI overview.

Contents
Requirement: Node.js 18+ (native fetch) or modern browser

1. Sending SMS

Check credentials

async 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();
}

Credit balance

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();
}

Estimate credits

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();
}

Simple SMS (GET)

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();
}

Advanced SMS (POST)

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();
}

Personalized SMS with RecipientsEx

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();
}

Deactivate pending SMS

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();
}

2. Delivery Webhooks

Webhooks are called exclusively via HTTP GET. Placeholders: <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();
}

Delivery Status (DST)

ValueMeaning
-1Not yet submitted / rejected
0Delivered
1Buffered
2Not Delivered

After status 1 (Buffered) you almost always get a second call with 0 or 2.

Common Reason Codes (RSN)

CodeMeaningTypical cause
000Unknown SubscriberNumber does not exist
103Call BarredBlocked / empty prepaid
107Absent SubscriberPhone off / no network
108Delivery FailMemory full or final failure
110Protocol ErrorDevice problems
118System failSevere network/device issues

3. Sendlog, Statistics & Two-Way

Daily traffic

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();
}

Send log by date

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();
}

Send log by MSISDN / TRN / JobID

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();
}

Inbox (received SMS)

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();
}

Receive URL (push for inbound SMS)

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();
}

4. Delivery Statistics per Recipient

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();
}

5. Phonebook

5.1 Phone numbers

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();
}

5.2 Groups

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();
}

5.3 Group relations

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();
}

6. Jobs

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();
}

7. Templates

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();
}