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.

403 Forbidden

SOLVED
Go to solution
Highlighted
Occasional Participant

403 Forbidden

I read through most of the forums and tried all the fixes and I'm still getting an error. Our registration process is classic asp/vbscript and I've used the following code:

 

FirstName=fname 
LastName=lname 
EmailAddress=email 
PostalCode=zip 
UN = "myheroproject" 
PW = "[pw]"
OptInSource="ACTION_BY_CUSTOMER" 
API_Key = "f504fafc-[...]6050" 
List_ID="1"

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
strPostData="<entry xmlns=""http://www.w3.org/2005/Atom"">"&vbcrlf&_
"<title type=""text""> </title>"&vbcrlf&_
"<updated>"&date()&"</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>"

Response.Write(strPostData & "<hr>")


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 

 The XML generated is:

<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text"> </title>
<updated>9/15/2011</updated>
<author></author>
<id>data:,none</id>
<summary type="text">Contact</summary>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/">
<EmailAddress>flashvenomdesign@gmail.com</EmailAddress>
<FirstName>Bill</FirstName>
<LastName>Smith</LastName>
<PostalCode>92806</PostalCode>
<OptInSource>ACTION_BY_CUSTOMER</OptInSource>
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/myheroproject/lists/1" />
</ContactLists>
</Contact>
</content>
</entry>

This all looks pretty simple/straightforward, so I'm assuming the fix must be as well... I'm just using my general login/pass credentials and the API key I was given so... Any help would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Employee

Re: 403 Forbidden

Hey Jeanne,

 

The base url may be incorrect. The 403 you should be getting is:

Error 403: Basic Authentication is not available over HTTP

Change your base URL to

 

Base_URL="https://api.constantcontact.com/ws/customers/"&UN&"/"

Please let me know if this worked for you.

Ryan Davis
Quality Engineer

View solution in original post

5 REPLIES 5
Highlighted
Employee

Re: 403 Forbidden

Hey Jeanne,

 

The base url may be incorrect. The 403 you should be getting is:

Error 403: Basic Authentication is not available over HTTP

Change your base URL to

 

Base_URL="https://api.constantcontact.com/ws/customers/"&UN&"/"

Please let me know if this worked for you.

Ryan Davis
Quality Engineer

View solution in original post

Highlighted
Occasional Participant

Re: 403 Forbidden

That did the trick / made sense - thank you! One more question, if I change List_ID to "2" it gives me a bad request. I'm guessing the ID is not the same as the "Order" in my list manager. How do I know which list has which ID?

Highlighted
Occasional Participant

Re: 403 Forbidden

I just realized that the list ID is in the URL variable pairs when editing the list / logged into my account. I guess most programmers would be able to discover that :-)

Highlighted
Occasional Participant

Re: 403 Forbidden

Setting the List_ID="3" still gives me a bad request error however... any ideas?

Highlighted
Employee

Re: 403 Forbidden

Hey Jeanne,

 

You can get the list id from doing a GET to your list collection.  For ex:

 

https://api.constantcontact.com/ws/customers/{username}/lists

 This will return all your lists with names and ID's. It only shows 50 at a time but inside of lists you will see a next page URI which will show the following 50. 

 

I would take a look at our rest client as well here.


Let me know if this works for you

 

 

 

Ryan Davis
Quality 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