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 adding new contact

Occasional Participant

(403) Forbidden adding new contact

I am trying to add a new contact from an form but I am getting "The remote server returned an error: (403) Forbidden."


    Public Function AddContact(ByVal UserEmailAddress As String, ByVal ContactListNumber As Integer) As String
            Dim xml As String
            xml = "<?xml version='1.0' encoding='utf-8' ?>" & _
            "<entry xmlns=''>" & _
                "<title type='text'></title>" & _
                "<updated>2008-07-23T14:21:06.407Z</updated>" & _
                "<author></author>" & _
                "<id>data:,none</id>" & _
                "<summary type='text'>Contact</summary>" & _
                "<content type='application/vnd.ctct+xml'>" & _
                    "<Contact xmlns=''>" & _
                        "<EmailAddress>" & UserEmailAddress.ToString() & "</EmailAddress>" & _
                        "<OptInSource>ACTION_BY_CONTACT</OptInSource>" & _
                        "<ContactLists>" & _
                            "<ContactList id='[username]/lists/" & ContactListNumber.ToString() & "'/>" & _
                        "</ContactLists>" & _
                    "</Contact>" & _
                "</content>" & _

            ' Set up the request
            Dim request As HttpWebRequest
            request = WebRequest.Create("[username]/contacts/")
            Dim byteData As Byte() = UTF8Encoding.UTF8.GetBytes(xml.ToString())
            request.Method = "POST"
            request.ContentType = "application/atom+xml"
            request.ContentLength = byteData.Length
            request.Credentials = New NetworkCredential("[api key]%[username]", "[password]")

            ' Send the request
            Dim postStream As Stream
            postStream = request.GetRequestStream()
            postStream.Write(byteData, 0, byteData.Length)

            Dim response As HttpWebResponse
            response = request.GetResponse()

        Catch ex As WebException
            Return ex.ToString
        End Try
    End Function



Re: (403) Forbidden adding new contact

I'm not noticing anything right away that would cause a 403, but POSTs to create a new contact should be sent to the URI, instead of Typically this returns a 404, but it's possible this could be causing your error.


Would you be able to try with this alternate URI, and let us know if you're still seeing the same issue?


Nick Galbraith
Support Engineer
Occasional Participant

Re: (403) Forbidden adding new contact

Thanks for your response Nick.

After changing the URI, I am now getting 


The remote server returned an error: (401) Unauthorized.




Re: (403) Forbidden adding new contact

The 401 error will come up when there is a mismatch between the username in the URI and the username in the authentication, or when the password is incorrect. I would suggest troubleshooting with RESTClient. If that program doesn't help, you can email with your full code, and we can troubleshoot privately.


Nick Galbraith
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