I'm unable to send an SMS via Twilio API. I got the exception below:
ERROR : Unauthorized endpoint, please check Setup->Security->Remote site settings endpoint: url
global class SampleSMSTest {
@future(callout=true)
public static void testsms() {
try {
String account = 'xxxxxxxxx';
String token = 'xxxxxxxxxx';
TwilioRestClient client = new TwilioRestClient(account, token);
Map<String, String> params = new Map<String, String> {
'To' => '+91953835xxxx',
'From' => '+1920569xxxx', // twilio registered number
'Body' => 'Hello there!'
};
TwilioMessage message = client.getAccount().getMessages().create(params);
} catch (Exception e) {
System.debug('Main error==========>' + e);
}
}
}
This looks like Salesforce APEX code. Anytime you want to call an external URL from Salesforce, you need to set the URL as a safe remote site. The error message tells you exactly where to go in SF. Add the Twilio URL "api.twilio.com" to the list.