We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Status=Bad Request, StatusCode=400

Occasional Participant

Status=Bad Request, StatusCode=400

Hi All,

    i want to integrate constantcontact with salesforce using oauth authentication.for this i wrote a class 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 a response like Status=Bad Request, StatusCode=400.whats wrong in my code. plase any one can help me.


Thanks in advance




I looked at your code and I don't believe that oAuth is set up correctly with APEX which is the salesforce programming language.  From what I understand you will need to do quite a bit more than that.  The URI you are requesting needs to have parameters stored into the header which do not appear to be correct. 


You can find some more information about an oAuth library that I found on salesfoce.com development boards here.


Also you will need to take a look at our documentation for oAuith and what we require on our side here.


Please let me know if this helps.



Ryan Davis
Quality Engineer
Occasional Participant



   Thank u for ur reply.

             in this no need to install the packages.  i want this integration using apis only.any one can u please rectify my code.whats wrong in that one.


Thanks in advance


If you are looking to use OAuth without the benefit of a 3rd party library or code package, you will need to implement the OAuth 1.0 standard as defined here: http://tools.ietf.org/html/rfc5849


Implementing this is beyond the scope of our forum support, we highly recommend the use of 3rd party code libraries or packages for doing this as OAuth is not a trivial authentication model to implement.  Your code is missing many attributes, such as all of the required OAuth parameters and the signature hash.


Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

View API documentation, code samples, get your API key.

Visit Page