3

I'm trying to invoke a service that sends a sms from a google apps script. The service wants the data in iso 8859-1. The code below send a message with the åäö as bad chars.

function sendSMS() {

  var doc = SpreadsheetApp.getActiveSpreadsheet();
  var cell = doc.getRange('b8');

  var payload = 
{
  "username" : "XXXX",
  "password" : "YYYY",
  "nr" : "0123123123",
  "type" : "text",
  "data" :  "Hello world...åäö" 

};

var options =
{
  "method" : "post",
  "payload" : payload
};

var response = UrlFetchApp.fetch("http://www.mosms.com/se/sms-send.php", options);
Browser.msgBox(response.getContentText());
}

function testFetch (){

var response = UrlFetchApp.fetch("http://www.google.com/");
Browser.msgBox(response.getContentText());

}
user1411045
  • 31
  • 1
  • 2
  • I think I've read a post on this some time ago but I don't remember exactly the details ;), have you searched the forum ? – Serge insas Dec 08 '12 at 20:16
  • Found it... but not the same context as your use case... sorry, nevertheless you can [have a look](http://stackoverflow.com/questions/11266469/docslist-file-getcontentasstring-missing-unicode-characters) to see if it helps – Serge insas Dec 08 '12 at 21:15

1 Answers1

2

As mentioned in the other question that Serge linked to in the comments, you can change the encoding of a string by first converting it to a Blob and then using the getDataAsString() method:

var result = Utilities.newBlob('Hello World').getDataAsString('ISO-8859-1');
Eric Koleda
  • 12,420
  • 1
  • 33
  • 51