Reply
Occasional Contributor
MarietjieW
Posts: 3
Registered: ‎12-29-2011

Last name

[ Edited ]

Hi I am using:

 

  Public Function AddUserToConstantContactList(ByVal UserEmailAddress As String, ByVal ContactListName As String) As String
        Try
            Dim WebClient As New System.Net.WebClient
            WebClient.QueryString.Add("loginName", "dentalladies")
            WebClient.QueryString.Add("loginPassword", "[PASSWORD]")
            WebClient.QueryString.Add("ea", UserEmailAddress)
            WebClient.QueryString.Add("ic", ContactListName)
               Dim Reader As New IO.StreamReader(WebClient.OpenRead("http://api.constantcontact.com/0.1/API_AddSiteVisitor.jsp"))
            Dim ResultHTML As String = Reader.ReadToEnd
            Return ResultHTML

        Catch ex As Exception
            Return ex.ToString
        End Try
    End Function

 

to add a new contact, how do I also add the last name? What is they query string for that? If I use             WebClient.QueryString.Add("LastName", txtLast.Text) it does not work?

 

Please Help,

 

Thanks

Richard_M
Posts: 30
Topics: 0
Kudos: 1
Solutions: 3
Registered: ‎02-15-2011

Re: Last name

Hi Marietjie,

 

It looks like you are using the older Site Visitor API for this script. We recommend switching to the new API in order to ensure continued functionality. I have written you a new function that you can use:

 

Public Function AddUserToConstantContactList(ByVal UserEmailAddress As String, ByVal ContactListNumber As Integer) As String
	Try
		Dim xml As String
		xml = "<?xml version='1.0' encoding='utf-8' ?>" & _
		"<entry xmlns='http://www.w3.org/2005/Atom'>" & _
		"<title type='text'></title>" & _
		 "<updated>2008-07-23T14:21:06.407Z</updated>" & _
		 "<author></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>" & UserEmailAddress.ToString() & "</EmailAddress>" & _
		   "<OptInSource>ACTION_BY_CONTACT</OptInSource>" & _
		   "<ContactLists>" & _
		 "<ContactList id='http://api.constantcontact.com/ws/customers/dentalladies/lists/" + ContactListNumber.ToString() + "'/>" & _
		   "</ContactLists>" & _
		  "</Contact>" & _
		 "</content>" & _
		"</entry>"

		' Set up the request
		Dim request As HttpWebRequest
		request = WebRequest.Create("https://api.constantcontact.com/ws/customers/dentalladies/contacts")
		Dim byteData As Byte() = UTF8Encoding.UTF8.GetBytes(xml.ToString())
		request.Method = "POST"
		request.ContentType = "application/atom+xml"
		request.ContentLength = byteData.Length
		request.Credentials = New NetworkCredential("Your API key%your user name", "your password")

		' Send the request
		Dim postStream As Stream
		postStream = request.GetRequestStream()
		postStream.Write(byteData, 0, byteData.Length)

		Dim response As HttpWebResponse
		response = request.GetResponse()

	Catch ex As WebException
		Return ex.ToString
	End Try
End Function

Also, the new API uses numbers to specify the list. So, you will need to pass in the number of the list to the function as a string.

Richard Maxwell
Support Engineer, Constant Contact