function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
charan@appscharan@apps 

REST API Integration to send sms

Hi

 

We want to send an sms from Salesforce to Mobile through REST API

 

we used this code

 

Http http = new Http(); HttpRequest req = new HttpRequest();

req.setEndpoint('https://Account ID:Auth token@api.twilio.com/2010-04-01/Accounts');

req.setMethod('GET');

String username = 'xxxxxxxxxxxxxxxxxx';

String password = 'yyyyyyyyyyyyyyyyyyy';

Blob headerValue = Blob.valueOf(username + ':' + password);

String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);

req.setHeader('Authorization', authorizationHeader);

req.setBody('hai'); HTTPResponse res = http.send(req);

System.debug('STATUS:'+res.getStatus());

System.debug('STATUS_CODE:'+res.getStatusCode());

System.debug('----Responce----'+res.getBody());

 

 

but it gives status 401 notfound error how can we do Plz help me

 

how can we overcome this, Please post your reply at earliest.

 

Pat PattersonPat Patterson

It looks like you're trying to do basic authentication in two places. Try changing your second line of code to

 

req.setEndpoint('https://api.twilio.com/2010-04-01/Accounts');

 

 

nagalakshminagalakshmi

Hi Charan,

 

Did you solve this issue... If solve, can you tell me please how can i send sms to mobiles through salesforce. Please help me.

 

Thanks,

Lakshmi

Yogeshwar Tailor 17Yogeshwar Tailor 17
        Hii All,
        Please try this....!!

        String account = 'Your twilio Account Sid';
        String token = 'Your twilio Auth token';
     
        HttpRequest req = new HttpRequest();
        req.setHeader('X-Twilio-Client', 'salesforce-' + '2010-04-01');
        req.setHeader('User-Agent', 'twilio-salesforce-' + '2010-04-01');
        req.setHeader('Content-Type', 'Application/JSON');
        req.setHeader('Authorization', 'Basic '+ EncodingUtil.base64Encode(Blob.valueOf(account + ':' +token )));
        req.setEndpoint('https://api.twilio.com'+'/'+'2010-04-01'+'/Accounts/'+account+'/SMS/Messages.json');
        req.setMethod('POST');
        req.setBody(''
               + 'From=' + EncodingUtil.urlEncode('+14242752341', 'UTF-8')
               + '&To=' + EncodingUtil.urlEncode(recievernumber, 'UTF-8')
               + '&Body=' + EncodingUtil.urlEncode('Type Message here', 'UTF-8')
               );
        HttpResponse res = new Http().send(req);
        
        //check response 
        if (res.getStatusCode() >= 200 && res.getStatusCode() < 300) {
            System.debug('This is the response '+res.getBody());
         }
MsgClubMsgClub
Hello all,
MsgClub (http://www.msgclub.net/)’s SMS API integration allows you to integrate SMS services with the Salesforce software you use. In this highly competitive online environment, having SMS API integration in Salesforce software is proving to be a measurable advantage.