2

I have got SMS sending working within Google Sheets with Twilio using a slight modification to the code below (I have changed SMS payload fields and API key references)

The code is executing but I am just not getting the SMS, I tried digging into the logs in the dashboards on Nexmo platform but not error logs were showing.

Looks like a slight tweak needed on the authentication perhaps? Here are the API/payload sections where I think the error lies:

NEXMO

(WORKING CODE BELOW)

Can any Nexmo users spot an issue with the authentication that may fix this?

sigur7
  • 796
  • 1
  • 11
  • 35
  • Usually failed authorization results in a 401 Unauthorized or 403 Forbidden error – tehhowch Jul 20 '18 at 22:35
  • 1
    What do you expect adding things to `options` to do? `UrlFetchApp` does not take everything in the `params` argument and make them into a querystring and then append that to the given URL... https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#fetchurl-params – tehhowch Jul 21 '18 at 15:02

2 Answers2

1

For the Nexmo SMS API, the credentials must be provided as GET parameters rather than via Basic auth. Your key should be in a parameter named api_key and secret in api_secret. See https://developer.nexmo.com/api/sms for more details on how the API works.

See also their guide on Authorization.

tehhowch
  • 9,645
  • 4
  • 24
  • 42
Michael Heap
  • 371
  • 1
  • 2
  • Thanks, Michael. Tried a few variants with no luck. Here is what I am currently working with edited in the post above. – sigur7 Jul 21 '18 at 14:34
1

This is the working code

  var payloads = {
    'to': mobileNumber,
    'text': smsMessage,
    'from': nexmoNumber,
    'api_key':api_key,
    'api_secret':api_secret
  };


  var messagesUrl = 'https://rest.nexmo.com/sms/json?' +api_key;
  var options = {
    'contentType': 'application/json',
    'method':'post',
    'payload': JSON.stringify(payloads)
  };

  var response = UrlFetchApp.fetch(messagesUrl,options);
  Logger.log(response.getContentText());
sigur7
  • 796
  • 1
  • 11
  • 35