The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

ASP adding contact

Highlighted
Occasional Contributor

ASP adding contact

 

Hi, I am trying to add email to my list for last 3 days, and I keep getting:

0 :Bad Request. Check Submitted Data

 

I have changed all the variable but with no luck.

Can anyone tell me what I am doing wrong here

 

 

<%FirstName="amber" //Your Contact's First Name
LastName="jones" //Your Contact's Last Name
EmailAddress="JOHN2@sammoon.com" //Your Contact's Email Address
PostalCode="75234" //Your Contact's Zip Code
UN = "SOMTHING" //Your Account Username
PW = "MYPASSWORD" //Your Account Password
'OptInSource="ACTION_BY_CONTACT" //The Actoin Type, usually as listed
OptInSource="ACTION_BY_CUSTOMER" //The Actoin Type, usually as listed
API_Key = "8d217aaf-f3555-46e0-b3244f-fc3443d7c4ff" //Your API Key
List_ID="2" //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="https://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

 


   

 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 "Content-type", "application/atom+xml"
    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 "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
%>

 

 

 

I really appreciate your help.

thank you

7 REPLIES 7
Highlighted
Trusted Contributor

Re: ASP adding contact

Hello if you can dump the XML that this code produces and email it to me, I would be happy to mock up your reuqest in RESTClient (using the approch shown here). Using RESTClient, the response body will be easily read, rather than interpretted into a new error message by your code's error handling, and usually this includes more specific information about the the cause of the error. We encourage developers to use RESTClient to troubleshoot requests for this reason, as it can be a very helpful troubleshooting tool for API requests.

Mark Coleman
Support Engineer
Highlighted
Occasional Contributor

Re: ASP adding contact

Thanks for your reply. does this App for with windows?  I downloaded but there is not install or exe file. It seems to be Apache License.

thanks again

Dean

Highlighted
Occasional Contributor

Re: ASP adding contact

Hi Mark, I finaly found the windows version and after duming it to this app, it gave me this:

POST /CCEMAIL3.ASP HTTP/1.1
Content-Length: 0
Content-Type: text/plain; charset=UTF-8
Host: sammoon.com
Connection: Keep-Alive
User-Agent: RestClient-Tool


HTTP/1.1 200 OK
Cache-control: private
Date: Thu, 19 Jul 2012 20:59:45 GMT
Content-Length: 36
Content-Type: text/html
X-Powered-By: ASP.NET
Server: Microsoft-IIS/6.0

0 :Bad Request. Check Submitted Data


0 :Bad Request. Check Submitted Data

Highlighted
Trusted Contributor

Re: ASP adding contact

With the windows GUI version of RESTClient, make your request, and use the save options to save the Request-Restponse Archive. You can email that to me at webservices@constantcontact.com, so I can have a closer look and maybe offer some additional guidance.

Mark Coleman
Support Engineer
Highlighted
Occasional Contributor

Re: ASP adding contact

I just emailed you the attachment. you should have it by now

Thank you

dean

Highlighted
Trusted Contributor

Re: ASP adding contact

Yes Dean,

 

Thank you. I've responded to you via our support ticket system. I hadn't realized this was the same request here on the forum. The details from RESTClient that you posted above are the headers. If you are using the GUI version for windows, you find the additional detail regarding the source of the error in your request by clicking the body tab in the response section at the bottom of the RESTClient window.

Mark Coleman
Support Engineer
Highlighted
Trusted Contributor

Re: ASP adding contact

For Windows, make sure you've downloaded the GUI version of RESTClient (the non-Mac download package). If you have the up-to-date Java Runtime Enviroment (Java Virtual Machine) installed, the jar file that you download should be directly executable by doubl-clicking it. There is no installation process other than copying it to the folder you want to keep it in, and creating your own shortcut to it, if you want.

Mark Coleman
Support Engineer
Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured