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);
}
}
}
Add the Twilio URL in sandbox as following path
Administration Setup > Security Controls > Remote Site Settings > click "**New Remote Site**" button.
I have re-solved my problem
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.
On my salesforce lightning page, I do these steps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.