Showing results for 
Search instead for 
Did you mean: 
Constant Contact wants to help you succeed! We’re celebrating our professional service programs on the Constant Contact Community this month and you have a chance to try one of the services for free! Learn more.

API Access error : The remote server returned (401) Unauthorized.

Occasional Visitor

API Access error : The remote server returned (401) Unauthorized.

HI ,



I am trying to access the events though api, but it is returning some error .  My requirement is that , i need to list all events in my web site , please check  my code below



string sUsername = "*****";       

string sPassword = "*****";       

string sAPIKey = "*******";


string sUri2 = "" + sUsername.ToLower() + "/events";


Uri addy = new Uri(sUri2);       

HttpWebRequest request = WebRequest.Create(addy) as HttpWebRequest;       

request.Credentials = new NetworkCredential((sAPIKey + "%" + sUsername), sPassword);       

request.Method = "GET";       

request.Accept = "application/atom+xml";       

request.ContentType = "application/atom+xml";       

HttpWebResponse response = request.GetResponse() as HttpWebResponse;       

StreamReader srResponse = new StreamReader(response.GetResponseStream());       

string xml = srResponse.ReadToEnd().ToString();



Tags (1)
CTCT Employee

Re: API Access error : The remote server returned (401) Unauthorized.

I think this will do what you are looking for. Please let me know if this resolves your issue?


string sUsername = "YOUR USERNAME";
string sPassword = "YOUR PASSWORD";
string sAPIKey = "YOUR API KEY";

NetworkCredential loginInfo = new NetworkCredential(sAPIKey + "%" + sUsername, sPassword);

HttpWebRequest ctctRequest = (HttpWebRequest)WebRequest.Create(""+sUsername+"/events");
ctctRequest.Method = "GET";
ctctRequest.Credentials = loginInfo;
ctctRequest.Accept = "application/atom+xml";

HttpWebResponse ctctResponse = ctctRequest.GetResponse() as HttpWebResponse;
StreamReader responseStream = new StreamReader(ctctResponse.GetResponseStream());
string responseText = responseStream.ReadToEnd();


David J