Sample ASP Code

Participant

Sample ASP Code

Would it be possible to get samples of the APIs in Classic ASP?
7 REPLIES 7

We would also be interested in getting a sample used in Classic ASP using VBScript.
Frequent Participant

There is a sample posted here.
Tom M
Group Product Manager – Content Editing
Constant Contact
Occasional Participant

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
Base_URL="http://api.constantcontact.com/ws/customers/"&UN&"/"

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=""http://www.w3.org/2005/Atom"">"&vbcrlf&_
"<title type=""text""> </title>"&vbcrlf&_
"<updated>"&UpdateTimeStamp&"</updated>"&vbcrlf&_
"<author></author>"&vbcrlf&_
"<id>data:,none</id>"&vbcrlf&_
"<summary type=""text"">Contact</summary>"&vbcrlf&_
"<content type=""application/vnd.ctct+xml"">"&vbcrlf&_
"<Contact xmlns=""http://ws.constantcontact.com/ns/1.0/"">"&vbcrlf&_
"<EmailAddress>"&EmailAddress&"</EmailAddress>"&vbcrlf&_
"<FirstName>"&FirstName&"</FirstName>"&vbcrlf&_
"<LastName>"&LastName&"</LastName>"&vbcrlf&_
"<PostalCode>"&PostalCode&"</PostalCode>"&vbcrlf&_
"<OptInSource>"&OptInSource&"</OptInSource>"&vbcrlf&_
"<ContactLists>"&vbcrlf&_
"<ContactList id="""&Base_URL&"lists/"&List_ID&""" />"&vbcrlf&_
"</ContactLists>"&vbcrlf&_
"</Contact>"&vbcrlf&_
"</content>"&vbcrlf&_
"</entry>"


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", _
"application/atom+xml"
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
objWinHttp.Send(strPostData)
If Err.Number = 0 Then
If objWinHttp.Status = "200" Then
PostDataToURL = objWinHttp.ResponseText
Else

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
Else
PostDataToURL = "Error " & Err.Number & " " & Err.Source & " " & _
Err.Description
End If
On Error GoTo 0
Set objWinHttp = Nothing
End Function


%>
Regular Participant

I need help setting with two things:

 

1. set up my ASP page posting information my classic ASP form to Constant Contact so users can subscribe/unsubscribe directly from my site

 

The link above by a CC employee links to the main developer page that has no sample code for classic ASP. For the most part, I understand the sample shown here regarding ASP and PHP, but since I'm not familiar with PHP, I don't fully understand what it is doing. Can someone please post a very simple code for classic ASP?

Hi,

 

Sorry for the dead link above.  Our .NET sample contact forms are here now:

 

https://github.com/constantcontact/Constant-Contact-Dot-Net-ASP-Contact-Forms

 

Best Regards,

Shannon W.

API Support Specialist

Regular Participant

Thanks - I see the ASP.NET files, but no classic ASP.

Sorry about that.  We don't have any supported classic ASP examples.

 

Best Regards,

Shannon W.

API Support Specialist

Developer Portal

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

Visit Page