Error media not supported

Regular Participant

Error media not supported

Trying to add a new contact list, just a list name. didn't find details on this in docs. We get a Media not supported error when trying this code. Can you offer help?


Public Shared Sub AddNewContactList(ByVal sListName As String)
        'Setup your variables
        Dim ctu As String = GetCTU()
        Dim ctp As String = GetCTP()
        Dim sUri As String = "" & ctu & "/activities"
        Dim sListUri As String = sListName 
        Dim sAPIKey As String = "CONSTANT_CONTACT_API_KEY"
            'Setup an HttpWebRequest to send the data
            Dim address As New Uri(sUri)
            Dim request As HttpWebRequest = TryCast(WebRequest.Create(address), HttpWebRequest)
            request.Credentials = New NetworkCredential((sAPIKey & "%" & ctu), ctp)
            request.Method = "POST"
            request.ContentType = "application/vnd.ctct+xml"

            'Build an encoded string of the data to pass to Constant Contact
            Dim data As New StringBuilder()
            'data.Append("activityType=" + HttpUtility.UrlEncode("SV_ADD", Encoding.UTF8))
            data.Append("&data=" + HttpUtility.UrlEncode(("OptInDefault,Name" & Chr(10)), Encoding.UTF8))
            data.Append(HttpUtility.UrlEncode(("true," & sListName), Encoding.UTF8))
            'data.Append("&lists=" + HttpUtility.UrlEncode(sListUri))

            'The "guts" of the code to execute the request and return a response
            Dim byteData As Byte() = UTF8Encoding.UTF8.GetBytes(data.ToString())
            Dim st As String = String.Empty

            request.ContentLength = byteData.Length
            Using postStream As Stream = request.GetRequestStream()
                postStream.Write(byteData, 0, byteData.Length)
            End Using

            Using response As HttpWebResponse = TryCast(request.GetResponse(), HttpWebResponse)
                Dim reader As New StreamReader(response.GetResponseStream())
                st = reader.ReadToEnd()
            End Using
        Catch ex As Exception
        End Try

    End Sub



Sorry for that error on the <ContactList> node, that was a copy/paste error on my part.  The correct resource, which is the one in my code snippet, is:{username}/lists


Activities would correctly give you a 415 Unsupported Media Type as it doesn't allow a POST request with the content type of application/atom+xml.  However, the lists collection does support that type (requires it in fact) and should not give you a 415 error if you're posting against that.

Dave Berard
Senior Product Manager, Constant Contact



It looks like the missing tag and the incorrect URI were the problems. I changed the uri to lists and it worked.


Thank you very much for your help.

Developer Portal

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

Visit Page