I'm trying to send sms from google sheet using the following code. I'm having the problem with the following line where I cannot sent requests to my sms portal.
my SMS userid is adam
password is 1234
API key is: xxxxxxxxxxxxxxxx
Code: Select all
"Authorization" : "Basic " + Utilities.base64Encode("YOURACCOUNTSID:YOURAUTHTOKEN")
Code: Select all
function sendSms(to, body) {
var messages_url = "https://smss/V123";
var payload = {
"To": to,
"Body" : body,
"source":"googleappsscript"
};
var options = {
"method" : "post",
"payload" : payload
};
options.headers = {
"Authorization" : "Basic " + Utilities.base64Encode("YOURACCOUNTSID:YOURAUTHTOKEN")
};
UrlFetchApp.fetch(messages_url, options);
}
function sendAll() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2;
var numRows = sheet.getLastRow() - 1;
var dataRange = sheet.getRange(startRow, 1, numRows, 2)
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
try {
response_data = sendSms(row[0], row[1]);
status = "sent";
} catch(err) {
Logger.log(err);
status = "error";
}
sheet.getRange(startRow + Number(i), 4).setValue(status);
}
}
function myFunction() {
sendAll();
}