Classic ASP and Javascript

New Member

Classic ASP and Javascript

Is anyone using Javascript on a classic ASP page to post/add contacts to a list? I can't find any examples in the forums.
I've found a php example and the XML it posts, but we don't run PHP on our server, so I'd be using winHTTP to Post the data and it will be in variable/value pairs (...&userName=blah&passWord=blah). If I pass the XML like that, can the API parse the XML values?

Any help would be appreciated.

I'm not sure I completely

I'm not sure I completely understand the question. winHTTP should support basic authentication by passing it the Username and Password when creating it. You can also use xmlHTTP for classic ASP. Both should allow you to set the authentication in the class creation. After that, you just need to open the connection and send the XML as the request.

If you want more information on how to use the winHTTP class, see this link to the MSDN help files on the syntax for VBScript and C++.
Dave Berard
Senior Product Manager, Constant Contact
Occasional Participant

Classic ASP code

wrote this up today. amalgamation of what worked in PHP and the ASP classic winHTTP methods. fully reusable function..

FirstName="Contact_First_Name" //Your Contact's First Name
LastName="Contact_Last_Name" //Your Contact's Last Name
EmailAddress="Contact_Email" //Your Contact's Email Address
PostalCode="Contact_Zip_Code" //Your Contact's Zip Code
UN = "ConstantContact_User_Name" //Your Account Username
PW = "ConstantContact_Password" //Your Account Password
OptInSource="ACTION_BY_CUSTOMER" //The Actoin Type, usually as listed
API_Key = "ConstantContact_API_Key" //Your API Key
List_ID="1" //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,FirstName,LastName,EmailAddress,PostalCode, "POST", UN,PW,API_Key))

Function PostDataToURL(List_ID,FirstName,LastName,EmailAddress,PostalCode, 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 date()
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&":Contact Already Exists"
case "201"
PostDataToURL="1"&vbtab&":Contact Successfully added"
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

New Member

code does not work for the second list

Excellent code

Was checking it out

Have created two lists 1) general interest and 2) sarab

using the code I was able to add to the first list ie general interest

but I was not able to add to the second list

All I changed in the program above after putting my api key, username, password  was List_ID="2"

After doing that I got the error code 400

Secondlyl I would like to know what is the meaning of this

OptInSource="ACTION_BY_CUSTOMER" is this a contstant or can it change

New Member

Sample ASP Code

Here's an ASP class that I wrote to add an email address to a mailing list:


CLASS FILE: clsConstantContact.asp


Class ConstantContact


    Private CC_URL, CC_LoginName, CC_LoginPassword, CC_API, objRequest, strResponseText

    Public CCAction, CCMailingList, CCEmailAddress


    Public Function CCSubmitRequest()

      CC_URL = ""

      CC_LoginName = "<enter your Constant Contact login>"

      CC_LoginPassword = "<enter your Constant Contact password>"


      CC_API = CC_URL & CCAction & "SiteVisitor.jsp?loginName=" & CC_LoginName & "&loginPassword=" & CC_LoginPassword & "&ea=" & CCEmailAddress & "&ic=" & CCMailingList

      Set objRequest = CreateObject("Microsoft.XMLHTTP")

      objRequest.Open "GET", CC_API, False


      strResponseText = objRequest.ResponseText


      Set objRequest = Nothing


      CCSubmitRequest = strResponseText


    End Function


  End Class



  <!--#include file="clsConstantContact.asp"-->

  Set objConstantContact = New ConstantContact

  objConstantContact.CCAction = "Add"

  objConstantContact.CCMailingList = "<enter your mailing list>"

  objConstantContact.CCEmailAddress = "<enter the email address you want to add>"

  strCCResult = objConstantContact.CCSubmitRequest()

  Set objConstantContact = Nothing


That's it.


"So shines a good deed in a weary world." - Willy Wonka

New Member

OptInSource definition...

Sorry for the extraordinary late reply as I just started with this, but I found what your looking for:


There are two options for <OptInSource> elements: ACTION_BY_CONTACT and ACTION_BY _CUSTOMER.  If the contact is adding himself or herself, use ACTION_BY_CONTACT.  If you are adding the contacts on their behalf, use ACTION_BY_CUSTOMER.  Please note that if you use ACTION_BY_CONTACT, a welcome letter, as specified in your account, will be sent out to them.

Contacts who are added with "ACTION_BY_CUSTOMER" do not receive a welcome email. This value MUST be used whenever the contact is being added by anyone other than the contact themselves. Contacts who are added with "ACTION_BY_CUSTOMER" will receive AutoResponder sequences based on the settings of the list they are being added to. Contacts who are added with "ACTION_BY_CUSTOMER" are not included on your "Visitor Signup Report".

Contacts who are added with "ACTION_BY_CONTACT" receive a welcome email. This value *CAN ONLY* be used if the contact is being added as a direct result of an action by the contact themselves (ie they are adding themselves via a public web form). Contacts who are added with "ACTION_BY_CONTACT" will receive AutoResponder sequences. Contacts who are added with "ACTION_BY_CONTACT" are included on your "Visitor Signup Report".

Developer Portal

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

Visit Page

Constant Contact Would Like To Hear From You!

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