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.

Basic authentication with Abdera client


Basic authentication with Abdera client

Hi all,

I'm trying to update my Abdera client application to use Basic authentication. Here is my basic code for initializing the client:

Abdera abdera = new Abdera();

AbderaClient client = new AbderaClient(abdera);

AbderaClient.registerTrustManager(); // needed for SSL

AbderaClient.registerScheme(AuthPolicy.BASIC, BasicScheme.class);



client.addCredentials(AuthScope.ANY_HOST, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME, new UsernamePasswordCredentials(apiKey + "%" + userName, password));

When I use the client to PUT however I get a 401: Unauthorized error. I've tested the same URL and credentials using RESTClient and they work fine. Any suggestions as to why it would not authorize properly?


Hi Gerald,


We unfortunately do not have any abdera experts on hand who may have more intimate knowledge of this language.  However, I believe that the correct syntax for ading a credential should be as follows (this could be the cause of your 401 unauthorized):


client.addCredentials("http://api.constantcontact.com", "realm", "basic", new UsernamePasswordCredentials(apiKey + "%" + userName, password));

The realm option should not matter in this case, however the domain and the scheme are important to set.  I am unsure how the headers are set for requests made with ANY_HOST and ANY_SCHEME and this may affect whether or not the API will accept the connection.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page