I try to create a new contact but I get an error (please see the attachment)
This is my code:
Public Function POST_Contact_FullInfo(ByVal XMLData As String) As String
Dim sPassword As String = My.Settings.API_password
Dim sUsername As String = My.Settings.API_username
Dim sAPIKey As String = My.Settings.API_Key
Dim sUri As String = "https://api.constantcontact.com/ws/customers/" & sUsername & str_Contact_uri
'setup httpWebReqeust to send the data
Dim theLoginCredentials As CredentialCache = New CredentialCache()
theLoginCredentials.Add(New Uri(sUri), "Basic", New NetworkCredential((sAPIKey & "%" & sUsername), sPassword))
Dim address As New Uri(sUri)
Dim theRequest As HttpWebRequest = TryCast(WebRequest.Create(address), HttpWebRequest)
theRequest.Credentials = theLoginCredentials
theRequest.Method = WebRequestMethods.Http.Post '"POST" '
theRequest.ContentType = "application/atom+xml"
theRequest.PreAuthenticate = True
''' I used the same credentials for getting data and they are ok.
Dim byteArray As Byte() = Encoding.ASCII.GetBytes(XMLData)
Dim XMLResponse As String = "" '= "Bytes to send: " + byteArray.Length
theRequest.ContentLength = byteArray.Length
'// Create a stream for the POST Request
Dim streamRequest As Stream = theRequest.GetRequestStream()
streamRequest.Write(byteArray, 0, byteArray.Length)
Dim reqResponse As HttpWebResponse
reqResponse = TryCast(theRequest.GetResponse(), HttpWebResponse)
Dim reader As New StreamReader(reqResponse.GetResponseStream())
XMLResponse = reader.ReadToEnd()
'// Close Reader
' End Using
'// Close the response to free up the system resources
Catch ex As Exception
Please help me with this.
It looks like the problems all involve bad XML. There were three errors in the 400 request with the ContactList node, one with the Contact node and you had redundant nodes of StateName and StateCode. Here is the corrected XML for the 400 request. The 500 request has similar problems that you can correct as well.
View API documentation, code samples, get your API key.Visit Page
We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...Read More