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=Unauthorized, StatusCode=401

Occasional Contributor

Status=Unauthorized, StatusCode=401

Hi All,

        i want to get contacts of constantcontact to salesforce.(integration of constantcontact with salesforce)for this i wrote a class like


public class Constantcontactws{public void invokeExternalWs(){Http h = new Http();    HttpRequest req = new HttpRequest();  final string username = 'ApiKey%Username';         final string password = 'Password';        Blob headerValue = Blob.valueOf(username);     String authorizationHeader = 'BASIC ' +EncodingUtil.base64Encode(headerValue);          req.setHeader('Authorization',authorizationHeader);           req.setHeader('Host','');    req.setHeader('Connection','keep-alive');    req.setHeader('Content-Type', 'application/atom+xml');    req.setMethod('POST');     req.setbody('');      req.setEndpoint('');      HttpResponse res = h.send(req);      system.debug('********'+res.getbody());



By running this class i got an exception like  Status=Unauthorized, StatusCode=401 .How to fix this one. any one can u please help me.



Thanks in advance.



Re: Status=Unauthorized, StatusCode=401

I updated your post to hide your username, password and API Key.  Please change your password ASAP for security purposes as other people may have seen this and now have access to your account.


Regarding the 401 error, it looks like the problem is that while you're setting the login information for your account, the request endpoint seems to be set to our sample code account, joesflowers.  You would correctly get a 401 error in this scenario because you don't have access to joesflowers account. 

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