- Constant Contact Community
- :
- Developer Community
- :
- Authentication and Access (ie. 401 errors!)
- :
- Re: Unauthorized, StatusCode=401
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Unauthoriz ed, StatusCode =401
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-20-2011 03:37 AM
Hi all
My code is
public class constantcontact
{
public void conlist()
{
Http h = new Http();
HttpRequest req = new HttpRequest();
final string username = 'USERNAME';
final string password = 'PASSWORD';
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' +EncodingUtil.base64Encode(headerValue);
//String authorizationHeader =username+':'+password;
req.setHeader('Authorization',authorizationHeader) ;
//req.setHeader('Content-length', '1753' );
req.setHeader('Host','api.constantcontact.com');
req.setHeader('Connection','keep-alive');
req.setHeader('Content-Type', 'application/atom+xml');
req.setMethod('GET');
//req.setbody('https://api.constantcontact.com/ws/customers/USERN AME/contacts');
req.setEndpoint('https://api.constantcontact.com/ws/customers/USERN AME/contacts');
HttpResponse res = h.send(req);
system.debug('********'+res.getbody());
}
}
I wanna get all contacts from constant contact
but i am getting error like
Status=Unauthorized, StatusCode=401
An Authentication object was not found in the SecurityContext
Whats wrong inmy code please help me
Re: Unauthoriz ed, StatusCode =401
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-20-2011 12:43 PM
Hey Rejeshy,
I am going to look at your code but it may take me some time. I have modified it to hide your username and password. I would highly suggest changing it as many people could have seen it. I will get back to you as soon as i find a solution for you. Also i read in another post that you are trying to move your contacts into salesforce. If you want to do so you can use the tool that we provide for this that is located in your account. It is under CRM tools when you click on add and update contacts.
Support Engineer, Constant Contact
Re: Unauthoriz ed, StatusCode =401
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-22-2011 02:15 PM
Hi Rajesh,
I looked into your code which was written with Apex from salesforce which is a language I am not all to familiar with. However I can see some errors in your code specifically with the connection. Please take a look at my exampl of my connection string:
String apikey = 'myapikey';
String username = 'myname';
String password = 'mypwd';
Blob headerValue = Blob.valueOf(apikey + '%' + username + ':' + password);
This should fix your 401 error.
Please let me know what the results are.
Support Engineer, Constant Contact


