cancel
Showing results for 
Search instead for 
Did you mean: 

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','https://api.constantcontact.com/ws/customers//contacts/1');    req.setHeader('Connection','keep-alive');    req.setHeader('Content-Type', 'application/atom+xml');    req.setMethod('POST');     req.setbody('https://api.constantcontact.com/ws/customers/Username/contacts');      req.setEndpoint('http://api.constantcontact.com/ws/customers/joesflowers/lists');      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.

 

1 REPLY 1
Moderator

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