The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Status=Bad Request, StatusCode=400

Highlighted
Occasional Contributor

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

3 REPLIES 3
Highlighted
Employee

Re: Status=Bad Request, StatusCode=400

Hey,

 

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
Highlighted
Occasional Contributor

Re: Status=Bad Request, StatusCode=400

Hi,

 

   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

 

Highlighted
Moderator

Re: Status=Bad Request, StatusCode=400

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

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured