1

I am trying to send SMS from Salesforce using Twilio's REST API. I keep getting below response.

{
    "code": 21605,
    "message": "The message body exceeds the 160 character limit.",
    "more_info": "https://www.twilio.com/docs/errors/21605",
    "status": 400
}

I am not getting any error when I send sms using Twilio console. So is it salesforce restricting me to send more then 160 char?

My sample request is:

HttpRequest req = new HttpRequest();
req.setEndpoint('https://api.twilio.com/2010-04-01/Accounts/'+accountSid+'/SMS/Messages.json');
req.setMethod('POST');
req.setHeader('Authorization','Basic '+EncodingUtil.base64Encode(Blob.valueOf(accountSid+':' +token)));
req.setBody('To='+EncodingUtil.urlEncode(phoneNumber,'UTF-8')+'&From='+EncodingUtil.urlEncode(fromPhNumber,'UTF-8')+'&Body='+mapOfPhoneNumberAndMessage.get(phoneNumber));
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug('=============SMS Body========='+res.getBody());

FYI - I can send SMS when message length is less then 160 char.

2

Salesforce isn't restricting the character limit. Try sending to '/Messages' instead of '/SMS/Messages'. This should allow up to 1600 characters.

https://www.twilio.com/docs/api/messaging/message

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.