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
anu123anu123 

Status=Bad Request, StatusCode=400

Hi all ,

     i want to integrate salesforce with constantcontact using oauth authentication. for this i wrote aclass like this.

 

 

public class Constantcontactoauth{public void invokeExternalWs(){Http h = new Http();   HttpRequest req = new HttpRequest();        final string username = 'Apikey%username%Consumer Secret';         Blob headerValue = Blob.valueOf(username);     String authorizationHeader = 'oauth' +EncodingUtil.base64Encode(headerValue);          req.setHeader('Authorization',authorizationHeader);           req.setHeader('Host','https://oauth.constantcontact.com/ws/oauth/request_token');    req.setHeader('Connection','keep-alive');    req.setHeader('Content-Type', 'application/atom+xml');    req.setMethod('POST');     req.setbody('https://oauth.constantcontact.com/ws/oauth/request_token');      req.setEndpoint('https://oauth.constantcontact.com/ws/oauth/confirm_access');           HttpResponse res = h.send(req);      system.debug(res.getbody());
}}

 

All credentials are valid. But i got an response like Status=Bad Request, StatusCode=400.whats wrong in my code.Please can any one help me.

 

Thanks in advance.

anu

Avi646Avi646

can you please attach the code using the attach code button. So that it will be readable enough

SFDC-vishnuSFDC-vishnu

Even i am facing same problem

HttpRequest req = new HttpRequest();        HttpResponse res = new HttpResponse();        Http http = new Http();         req.setEndpoint(URL);        req.setMethod('POST');        //setting header start               //req.setHeader('Accept-Encoding','gzip,deflate');               //application/soap+xml               //text/xml                req.setHeader('Content-Type','text/xml;charset=UTF-8');                req.setHeader('SOAPAction', 'http://tempuri.org/UploadDocument');              req.setHeader('User-Agent','Jakarta Commons-HttpClient/3.1');                //Blob headerValue = Blob.valueOf('customuser' + ':' + 'Ga%Ra$Na#');                 //String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);                //req.setHeader('Authorization', authorizationHeader);                                                //String requestString = '<<SOAP MESSAGE>>';                      //req.setHeader('Content-Length',String.valueOf(requestString.length()));        //setting header end      // req.setBody('fileName='+EncodingUtil.urlEncode(fileName, 'UTF-8')+'&filecontents='+EncodingUtil.urlEncode(contentType, 'UTF-8')+'&fileTitle='+EncodingUtil.urlEncode(fileTitle, 'UTF-8')+'&fileDescription ='+EncodingUtil.urlEncode(fileBodyEncoded, 'UTF-8')+'& salesForceUser ='+EncodingUtil.urlEncode(salesforceUser, 'UTF-8'));        req.setBody('fileName='+fileName+'&filecontents='+contentType+'&fileTitle='+fileTitle+'&fileDescription ='+fileBodyEncoded+'& salesForceUser ='+salesforceUser);        system.debug('req*********************'+req);        req.setCompressed(true); // otherwise we hit a limit of 32000        system.debug('****###############requestString'+req.tostring());                 try {                   res = http.send(req);               system.debug('****###############*************responseString'+res.tostring());        } catch(System.CalloutException e) {            System.debug('Callout error: '+ e);            System.debug(res.toString());        }       

 

SFDC-vishnuSFDC-vishnu

I am actually doing sharepoint integration

 

please let me know ,if any solution's

 

Thanks..