Send SMS from Google Sheets
Type a phone number and a text into a row, and a few minutes later the SMS goes out from your phone. A short Apps Script reads the sheet, calls the NS SMS API with UrlFetchApp and writes the status back next to each row.
Who this is for
- Small teams that keep customers, bookings or shifts in a spreadsheet.
- Anyone who wants to send a list of texts without writing an app.
Before you start
- An Android phone (8.0 or newer) with a SIM card that can send SMS.
- The NS SMS app from Google Play, set as the default SMS app, with "Accept API requests" turned on in the API tab.
- Your phone ID (device_id) and API key (nss_...) from the API tab. Below they appear as YOUR_DEVICE_ID and nss_YOUR_API_KEY.
- A Google account and a spreadsheet you can edit.
No account, email or password. Install the app, turn on the API and copy your phone ID and API key.
Setup, step by step
-
Step 1.Prepare the sheet
Name a sheet SMS and put the headers in row 1. Format column A as plain text (Format > Number > Plain text) before you type numbers, otherwise Sheets treats +14155550123 as a number or formula and drops the +.
| | A (phone) | B (text) | C (status) | D (message id) | | 1 | phone | text | status | id | | 2 | +14155550123 | Hi Anna, see you tomorrow at 10:00. | | | | 3 | +447700900123 | Your order is ready for pickup. | | | -
Step 2.Paste the script
Open Extensions > Apps Script, replace the content of Code.gs with the script below and save.
const API = 'https://sms-api.n-soft.pl/v1/sms'; const SHEET = 'SMS'; function props_() { const p = PropertiesService.getScriptProperties(); return { key: p.getProperty('NS_SMS_API_KEY'), device: p.getProperty('NS_SMS_DEVICE_ID') }; } // Sends every row that has a phone and a text but no status yet. function sendPendingSms() { const { key, device } = props_(); const sheet = SpreadsheetApp.getActive().getSheetByName(SHEET); const rows = sheet.getDataRange().getValues(); for (let i = 1; i < rows.length; i++) { const [phone, text, status] = rows[i]; if (!phone || !text || status) continue; const res = UrlFetchApp.fetch(API + '/send', { method: 'post', contentType: 'application/json', headers: { Authorization: 'Bearer ' + key }, payload: JSON.stringify({ device_id: device, to: String(phone).trim(), text: String(text) }), muteHttpExceptions: true, }); const body = JSON.parse(res.getContentText() || '{}'); if (res.getResponseCode() === 202) { sheet.getRange(i + 1, 3, 1, 2).setValues([[body.status, body.id]]); } else { sheet.getRange(i + 1, 3).setValue('error: ' + (body.error ? body.error.code : res.getResponseCode())); } Utilities.sleep(2100); // stay under 30 requests a minute } } // Updates the status column of messages that are not final yet. function refreshStatuses() { const { key } = props_(); const sheet = SpreadsheetApp.getActive().getSheetByName(SHEET); const rows = sheet.getDataRange().getValues(); const open = ['accepted', 'received', 'sent']; for (let i = 1; i < rows.length; i++) { const [, , status, id] = rows[i]; if (!id || !open.includes(status)) continue; const res = UrlFetchApp.fetch(API + '/' + id, { headers: { Authorization: 'Bearer ' + key }, muteHttpExceptions: true, }); if (res.getResponseCode() === 200) { const sms = JSON.parse(res.getContentText()); sheet.getRange(i + 1, 3).setValue(sms.error_code ? sms.status + ': ' + sms.error_code : sms.status); } Utilities.sleep(2100); } } -
Step 3.Store the key in script properties
Open Project Settings (the gear icon), scroll to Script properties and add NS_SMS_API_KEY and NS_SMS_DEVICE_ID with your values. The key stays out of the code, so you can share the script safely.
-
Step 4.Run it once
Pick sendPendingSms in the toolbar and click Run. Google asks you to allow the script to edit the spreadsheet and connect to an external service. After that, the status column fills with accepted and the message ID.
-
Step 5.Add time-driven triggers
Open Triggers (the alarm clock icon), click Add Trigger, choose sendPendingSms, event source Time-driven, Minutes timer, every 5 minutes. Add a second trigger for refreshStatuses every 15 minutes. Or run createTriggers once:
// Same as adding the triggers by hand in the Triggers panel. function createTriggers() { ScriptApp.newTrigger('sendPendingSms').timeBased().everyMinutes(5).create(); ScriptApp.newTrigger('refreshStatuses').timeBased().everyMinutes(15).create(); }
Check the status and receive webhooks
The send request answers 202 with a message ID right away. The status then moves through received (the phone has it), sent and delivered, or failed with an error code. You can ask for it with GET /v1/sms/{id}, or let the server POST every change to a webhook address that you set in the app (API tab). Webhooks work on every plan and also report usage.warning, usage.limit_reached, device.offline and device.online.
refreshStatuses asks GET /v1/sms/{id} for every row that is not final yet and writes delivered, or failed with the error code, into column C.
Webhooks are not a good fit here: Apps Script web apps cannot read request headers, so they cannot check the X-NS-Signature. Polling with the trigger is simpler and safe.
Troubleshooting
- A run of Apps Script stops after 6 minutes. With the 2-second pause (to stay under 30 requests a minute) that is about 150 rows per run; the next run continues, because sent rows already have a status.
- error: validation_failed in column C: the number lost its + or has spaces. Format column A as plain text and type the number again.
- To send later, add the date to the payload as send_at (ISO 8601 with a time zone, for example 2026-12-02T18:00:00+01:00).
- 401 unauthorized: the Authorization header must be "Bearer " followed by the key, and device_id must belong to that key.
- 403 api_disabled: open the app and turn on "Accept API requests" in the API tab.
- 422 validation_failed: the number must be in international E.164 format, with + and the country code (for example +14155550123), and the text at most 1,600 characters.
- 429: more than 30 requests a minute, or the daily or monthly cap of your plan (Free 50 a day, Pro 500, Business 1,000). The response says which one.
SMS API reference → SMS error codes → Plans and daily limits →