The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

400 error (with ASP code)

Highlighted

400 error (with ASP code)

Hi, 

 

I'm try to POST to https://api.constantcontact.com/ws/customers/############/contacts with the basic authentication. I'm programming ASP and I'm using the Microsoft.XMLHTTP with MSXML2.DOMDocument to load the xml and I am getting back 400 error.

 

Here is the code: 

 

serverUrl = "https://api.constantcontact.com/ws/customers/############/contacts"

set mrequest = server.CreateObject("Microsoft.XMLHTTP")
set xmlin = server.CreateObject("MSXML2.DOMDocument")
username = "############"
password = "############"
auth = "ODUwM2U1Y2MtNDdlYS00YmVhLTg1NTYtMzJkYWMxMWQxMzg2JW1heG1lbG9uaTpDb25zdGFudC4xMjM0"

 

txt = "<entry xmlns=" & chr(34) & "http://www.w3.org/2005/Atom" & chr(34) & ">" & vbcrlf

 

txt = txt & " <title type=" & chr(34) & "text" & chr(34) & "> </title>" & vbcrlf

 

txt = txt & " <updated>" & year(date()) & "-" & month(date()) & "-" & day(date()) & "T14:21:06.407Z</updated>" & vbcrlf

 

txt = txt & " <author>Max</author>" & vbcrlf

 

txt = txt & " <id>data:,none</id>" & vbcrlf

 

txt = txt & " <summary type=" & chr(34) & "text" & chr(34) & ">Contact</summary>" & vbcrlf

 

txt = txt & " <content type=" & chr(34) & "application/vnd.ctct+xml" & chr(34) & ">" & vbcrlf

 

txt = txt & " <Contact xmlns=" & chr(34) & "http://ws.constantcontact.com/ns/1.0/" & chr(34) & ">" & vbcrlf

 

txt = txt & " <EmailAddress>new_email@email.com</EmailAddress>" & vbcrlf

 

txt = txt & " <FirstName>First</FirstName>" & vbcrlf

 

txt = txt & " <LastName>Last</LastName>" & vbcrlf

 

txt = txt & " <OptInSource>ACTION_BY_CONTACT</OptInSource>" & vbcrlf

 

txt = txt & " <ContactLists>" & vbcrlf

 

txt = txt & " <ContactList id=" & chr(34) & "http://api.constantcontact.com/ws/customers/############/lists/1" &

chr(34) & " />" & vbcrlf

 

txt = txt & " </ContactLists>" & vbcrlf

 

txt = txt & " </Contact>" & vbcrlf

 

txt = txt & " </content>" & vbcrlf

 

txt = txt & "</entry>" & vbcrlf


xmlin.validateOnParse = true

result = xmlin.loadXML(txt)

Response.Write result & "<br>"

strRequest = xmlin.xml
Response.Write strRequest & "<br><br><br>"

 

if xmlin.parseError.errorcode <> 0 then
     Response.Write "<script>alert('CANCELLED.\n\n" & "An error occurred (" & xmlin.parseError.errorcode & ") during the validation of xml file a node level " & replace(xmlin.parseError.srcText, chr(34), "") & "');</script>"
else
     mrequest.open "POST", serverUrl, false
     mrequest.setRequestHeader "Content-Type", "application/atom+xml;type=entry"
     mrequest.setRequestHeader "Authorization", "Basic " & auth
     mrequest.send "xmlin=" & xmlin.xml

     if mrequest.Status = 200 then ' successful
          strResponse = mrequest.responseText
          Response.Write strResponse
     else ' failure
          Response.Write "<br>Error code received from server: " & mrequest.Status
     end if

end if

 

 

 

Thank you for your help!

 

Max

3 REPLIES 3
Highlighted
Employee

Re: 400 error (with ASP code)

Hi,

 

Could you please include the XML you are POSTing to our server?

 

Thanks,

Andrew Weber
Associate Product Manager for EventSpot
Highlighted

Re: 400 error (with ASP code)

Sure, here it is:

 

<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text"> </title>
<updated>2011-12-20T14:21:06.407Z</updated>
<author>UnitedShades.com</author>
<id>data:,none</id>
<summary type="text">Contact</summary>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/">
<EmailAddress>email@email.com</EmailAddress>
<FirstName>First</FirstName>
<LastName>Last</LastName>
<OptInSource>ACTION_BY_CONTACT</OptInSource>
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/maxmeloni/lists/1" />
</ContactLists>
</Contact>
</content>
</entry>

 

Highlighted
Employee

Re: 400 error (with ASP code)

Hey,

 

I tested your XML with my rest client and I received a 201.  Something must be changing somewhere in your code somehow.  I am not familiar with ASP but I will try to replicate it in Visual Studio this week.

Ryan Davis
Quality Engineer
Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured