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)
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
"<title type=""text""> </title>"&vbcrlf&_
"<ContactList id="""&Base_URL&"lists/"&List_ID&""" />"&vbcrlf&_
Set objWinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
objWinHttp.SetTimeouts lngTimeout, lngTimeout, lngTimeout, lngTimeout
If strMethod = "POST" Then
objWinHttp.setRequestHeader "Content-type", _
If strHostOverride <> "" Then
objWinHttp.SetRequestHeader "Host", strHostOverride
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
On Error Resume Next
If Err.Number = 0 Then
If objWinHttp.Status = "200" Then
PostDataToURL = objWinHttp.ResponseText
select case objWinHttp.Status
PostDataToURL="2"&vbtab&":Contact Already Exists"
PostDataToURL="1"&vbtab&":Contact Successfully added"
PostDataToURL="0"&vbtab&":Bad Request. Check Submitted Data: "
PostDataToURL = "0"&vbtab&":" & objWinHttp.Status & " " &objWinHttp.StatusText
PostDataToURL = "Error " & Err.Number & " " & Err.Source & " " & _
On Error GoTo 0
Set objWinHttp = Nothing
This is cool but I haven't been able to make it work. The problem may have more to do with the CC/Mashable auth business than how I'm trying to use the code. I already have an ASP page that imports downloaded web orders into our customer service database (none of this stufff was written by me). What I'd like to do is use this code to, while each order is being imported, stuff the customer info into a CC list for an auto-response email. I'm a programmer, but I don't have a lot of ASP experience, so I'm just figuring out things as I go along. But if I try to run this code as a test, it always fails with a 403 error. Which makes me think the API key/account info is what's causing it to fail. We're running IIS6, BTW.
This is basically just an internal bit of automation so that our customer service people don't have to query new order info into a spreadsheet and import that into a CC list.
Pete @ Clark Labs
The 403 is most often received when there is a mismatch between the username provided in the XML payload to us, and the username provided in the authentication details.
This code was written against our V1 API, which now has a limited shelf life (it will most likely be retired in 2014 or possibly later this year). If you try to use a Mashery (V2) API key with code written for the V1 API, you will get a 401 error, so go to this page to generate a V1 API Key if you'd still like to use this example as a starting point.
API Support Specialist
I'm past the auth issue - my Base_URL needed https
Now I'm getting in but I think my XML is funky, I'm getting:
0 :Bad Request. Check Submitted Data
See my response to your post here. This XML was written a little outside of what I'd consider normal. You probably want to either change the optinsource to action_by_customer, to move the contact to 'removed' status, or you want to add a contactList node so that the contact can actually be on a list.
API Support Specialist
View API documentation, code samples, get your API key.
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