I have looked at previous posts regarding the 401 error-- and solutions -- without any success.
What I have done is to create a VB.Net application that gets data in an XML format, creates an Excel file, and attempts to load it into a test list. Eveything goes great until I run the API, and I then receive a 401 error, even after I checked the API information (API Key, user name, password) sent.
I found one suggestion to use the URL https://api.constantcontact.com/ws/customers/<username>/contact that causes a prompt for the user ID and password to appear, but nothing that I have will authenticate. (using my actual user name where <username> is above, of course.
I can post my code here, but it is pretty much copied from the sample, and I am thinking that unless I can get the above link to work & authenticate, that it won't matter.
I would appreciate any direction you can provide.
Here is the code, if it helps, with the security stuff x'ed out:
<code>
Sub uCC(ByVal aData) Try Dim cUser As String = String.Empty & "username"
lCredntials.Add(
theRequest.Credentials = lCredntials
theRequest.Method =
theRequest.ContentType =
data.Append(
data.Append(
data.Append(HttpUtility.UrlEncode(Chr(10), Encoding.UTF8))
data.Append(HttpUtility.UrlEncode((l.ToString), Encoding.UTF8))
data.Append(
EncodedURITextBox.Text = data.ToString()
theRequest.ContentLength = byteData.Length
postStream.Write(byteData, 0, byteData.Length)
strResponse = reader.ReadToEnd()
ResponseTextBox.Text = strResponse
MsgBox(strResponse)
ResponseTextBox.Text = ex.Message
</code>
TIA
Private
If you are visiting https://api.constantcontact.com/ws/customers/<username>/contact, the prompt that comes up will be asking for your login credentials. The username for this would be in the format of apikey%username, and your password would be your typical Constant Contact password. If you are unable to access this resource with your credentials, I would recommend verifying that your login credentials are correct.
Please note that the username and password are for your Constant Contact account, and not your developer board account name. To verifying if you are using the correct username and password, you should be able to login to www.constantcontact.com using these credentials. If you are unable to login, then either your username or password are incorrect or have been modified.
If you are still unable receiving an error 401, please let me know and we can continue to troubleshoot further.
David J
I was not using the correct user name in my code (using the developer user, not the normal user). Now I am receiving the 400 Bad Request from the application. I will keep digging as I know other folks have reported this...and I will update here if I find a solution. In the meantime, I would appreciate any assistance you can offer.
After checking on the other 400 errors reported, I am looking at my excel file. All I have is an email Address in column A.
I am looking at this code:
<code>
data.Append("&data=" + HttpUtility.UrlEncode(("Email Address"), Encoding.UTF8))
For Each l In aData
data.Append(HttpUtility.UrlEncode(vbLf, Encoding.UTF8))
data.Append(HttpUtility.UrlEncode((l.ToString), Encoding.UTF8))
Next
</code>
I can look at the excel file fine and there appears to be no problems there.
Is there a way to directly import the XML?
Thanks!
OK, I ditched the Excel file, and created a txt file and got the following result:
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<Activity xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/username/activities/xxxxxx">
<Type>ADD_CONTACTS</Type>
<Status>PENDING</Status>
<TransactionCount>11631</TransactionCount>
<Errors>0</Errors>
<InsertTime>2010-06-13T01:23:41.732Z</InsertTime>
</Activity>
</content>
<link href="/ws/customers/username/activities/xxxxx" rel="edit"></link>
<id>http://api.constantcontact.com/ws/customers/username/activities/xxxxxx</id>
<title type="text">ADD_CONTACTS: Unnamed</title>
<updated>2010-06-13T01:23:41.732Z</updated>
<author>
<name>Constant Contact</name>
</author>
<link href="/ws/customers/username/activities/xxxxx" rel="edit"></link>
</entry>
I think it is good...will wait until later to check if the "PENDING" gets added to my test list!