Showing results for 
Search instead for 
Did you mean: 

Adding existing users to new lists

Occasional Participant

Adding existing users to new lists

I am using a form (asp vbscript) to add users to a new list on a site and the addition of new contacts works fine but if the user is already suscribed to another list I get a 409 error.  I understand that the xml I am sending is probabaly the issue but i have looked around on the forums have not found any vbscript sample for editing a contacts details and adding them to a new list if they are existant contact in other lists.  Here is the code I am using



'FirstName=Request.Form("name") //Your Contact's First Name

'LastName=Request.Form("last") //Your Contact's Last Name

EmailAddress=Request.Form("email") //Your Contact's Email Address

'Addr1=Request.Form("address") //Your Contact's Address

'City=Request.Form("city") //Your Contact's City

'StateName=Request.Form("state") //Your Contact's State

'CountryName=Request.Form("country") //Your Contact's Country

'PostalCode=Request.Form("zip") //Your Contact's Zip Code

'HomePhone=Request.Form("phone") //Your Contact's Phone

'CustomField1=Request.Form("CustomField1") //Your Contact's Gender

UN = "xxxxxxxxx" //Your Account Username

PW = "xxxxxxxxx" //Your Account Password

OptInSource="ACTION_BY_CONTACT" //The Action Type, usually as listed

API_Key = "76a1fba5-3562-4e06-83c4-xxxxxxxxxx" //Your API Key

List_ID="19" //Your Particular List ID,,1,2,3 & etc. (Default is 1, first user created would be 2, and so on)

response.write(PostDataToURL(List_ID,EmailAddress, "POST", UN,PW,API_Key))

Function PostDataToURL(List_ID,EmailAddress, strMethod, UN,PW,API_Key)

Dim lngTimeout

Dim strUserAgentString

Dim intSslErrorIgnoreFlags

Dim blnEnableRedirects

Dim blnEnableHttpsToHttpRedirects

Dim strHostOverride

Dim strLogin

Dim strPassword

Dim strResponseText

Dim objWinHttp

Dim entry

Dim Base_URL

Dim UpdateTimeStamp


lngTimeout = 59000

strUserAgentString = "http_requester/0.1"

intSslErrorIgnoreFlags = 0 ' 13056: ignore all err, 0: accept no err

blnEnableRedirects = True

blnEnableHttpsToHttpRedirects = True

strHostOverride = ""

strLogin = API_Key & "%" & UN

strPassword = PW

UpdateTimeStamp = Now()

strPostData="<entry xmlns="""">"&vbcrlf&_

"<title type=""text""> </title>"&vbcrlf&_




"<summary type=""text"">Contact</summary>"&vbcrlf&_

"<content type=""application/vnd.ctct+xml"">"&vbcrlf&_

"<Contact xmlns="""">"&vbcrlf&_




"<ContactList id="""&Base_URL&"lists/"&List_ID&""" />"&vbcrlf&_





Set objWinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")

objWinHttp.SetTimeouts lngTimeout, lngTimeout, lngTimeout, lngTimeout

objWinHttp.Open strMethod,Base_URL&"contacts"

If strMethod = "POST" Then

objWinHttp.setRequestHeader "Content-type", _


End If

If strHostOverride <> "" Then

objWinHttp.SetRequestHeader "Host", strHostOverride

End If

objWinHttp.Option(0) = strUserAgentString

objWinHttp.Option(4) = intSslErrorIgnoreFlags

objWinHttp.Option(6) = blnEnableRedirects

objWinHttp.Option(12) = blnEnableHttpsToHttpRedirects

If (strLogin <> "") And (strPassword <> "") Then

objWinHttp.SetCredentials strLogin, strPassword, 0

End If

On Error Resume Next


If Err.Number = 0 Then

If objWinHttp.Status = "200" Then

PostDataToURL = objWinHttp.ResponseText


select case objWinHttp.Status

case "409"

PostDataToURL="2"&vbtab&":Informacion de Contacto ya Existente"

case "201"

PostDataToURL="1"&vbtab&":Informacion de Contacto Añadida Exitosamente"

case "400"

PostDataToURL="0"&vbtab&":Bad Request. Check Submitted Data: "

case else

PostDataToURL = "0"&vbtab&":" & objWinHttp.Status & " " &objWinHttp.StatusText

end select

End If


PostDataToURL = "Error " & Err.Number & " " & Err.Source & " " & _


End If

On Error GoTo 0

Set objWinHttp = Nothing

End Function



Any help or direccion would be greatly appreciated.




The 409 error you're seeing

The 409 error you're seeing indicates that the Contact already exists (409 Conflict - Contact is already a subscriber).  You can not do a POST (create) in REST APIs when there is already an existing resource, you instead need to so an Update (PUT) to the Contact URI of the existing contact.  You can find out more information on how to update existing subscribers here.

Dave Berard
Senior Product Manager, Constant Contact
Occasional Participant

Sample Code

Do you have any sample code or templates that I could use for the edit/update operations?

CTCT Employee

The only sample scripts that

The only sample scripts that we have available are in PHP, .NET nad ColdFusion.


Perhaps another member here has a solution that they would like to share?

Dan H

Support Engineer, Constant Contact

Occasional Participant

How about sample XML

I think all really need to see is how the XML should look  in order to pull out the record for the contact and then the return message that would be sent back to the servers in order to update the record with the new list which I imagine that it would be the contacts current record in xml and the return would just append the new list to the original XML.  Thanks in advance any help would greatly be appreciated.


The XML should look exactly

The XML should look exactly the same as creating a contact with the single exception of having the ID node populated with the ID value for the contact (which is returned in a GET request or query).  The format is documented here with all of our Contacts Collection requestions.

Dave Berard
Senior Product Manager, Constant Contact