Note that there are some explanatory texts on larger screens.

plurals
  1. POConstant Contact API - (403) Forbidden adding new contact
    text
    copied!<p>I am trying to add a new contact to a mailing list using the Constant Contact API. I have a simple asp.net form and am executing the following function but I am getting "The remote server returned an error: (403) Forbidden." My function comes directly from Constant Contact but go figure!</p> <p><a href="http://community.constantcontact.com/t5/Getting-Started-with-API-s/Last-name/td-p/44749" rel="nofollow">Constant Contact API</a></p> <pre><code>Public Function AddContact(ByVal UserEmailAddress As String, ByVal ContactListNumber As Integer) As String Try Dim xml As String xml = "&lt;?xml version='1.0' encoding='utf-8' ?&gt;" &amp; _ "&lt;entry xmlns='http://www.w3.org/2005/Atom'&gt;" &amp; _ "&lt;title type='text'&gt;&lt;/title&gt;" &amp; _ "&lt;updated&gt;2008-07-23T14:21:06.407Z&lt;/updated&gt;" &amp; _ "&lt;author&gt;&lt;/author&gt;" &amp; _ "&lt;id&gt;data:,none&lt;/id&gt;" &amp; _ "&lt;summary type='text'&gt;Contact&lt;/summary&gt;" &amp; _ "&lt;content type='application/vnd.ctct+xml'&gt;" &amp; _ "&lt;Contact xmlns='http://ws.constantcontact.com/ns/1.0/'&gt;" &amp; _ "&lt;EmailAddress&gt;" &amp; UserEmailAddress.ToString() &amp; "&lt;/EmailAddress&gt;" &amp; _ "&lt;OptInSource&gt;ACTION_BY_CONTACT&lt;/OptInSource&gt;" &amp; _ "&lt;ContactLists&gt;" &amp; _ "&lt;ContactList id='http://api.constantcontact.com/ws/customers/[username]/lists/" &amp; ContactListNumber.ToString() &amp; "'/&gt;" &amp; _ "&lt;/ContactLists&gt;" &amp; _ "&lt;/Contact&gt;" &amp; _ "&lt;/content&gt;" &amp; _ "&lt;/entry&gt;" ' Set up the request Dim request As HttpWebRequest request = WebRequest.Create("https://api.constantcontact.com/ws/customers/[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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload