415 Error When Adding a New List in VB.Net

SOLVED
Highlighted
Advisor

415 Error When Adding a New List in VB.Net

Hi, (Using VB.Net 2010)

I found an HttpWebRequest example for VB.Net here:
http://www.808.dk/?code-vbnet-httpwebrequest

I've copied the significant parts.

When I run it, I receive a "415 Unsupported Media Type" error on request.GetResponse()

Here is my code:

   Dim strURI As String = "https://api.constantcontact.com/ws/customers/mycustomername/lists"
   Dim strCredentials As String = strCC_AppKey & "%" & strCC_LoginName
   Dim strListsURI As New Uri(strURI)
   Dim strXML As String = GetCreateListXML()
   Dim request As HttpWebRequest = WebRequest.Create(strListsURI)

   request.Credentials = New NetworkCredential((strCredentials), strCC_Password)
   request.ContentType = "application/x-www-form-urlencoded"
   request.Method = "POST"

   Dim encoding As New Text.UTF8Encoding() 'Use UTF8Encoding for XML requests

   Dim postByteArray() As Byte = encoding.GetBytes(strXML)

   request.ContentLength = postByteArray.Length

   Dim postStream As IO.Stream = request.GetRequestStream()

   postStream.Write(postByteArray, 0, postByteArray.Length)

   postStream.Close()

   Dim response As HttpWebResponse = request.GetResponse()



The strXML string looks like this:

<entry xmlns="http://www.w3.org/2005/Atom">
  <id>http://api.constantcontact.com/ws/customers/cascadedsdev/lists</id>
  <title type="text">Contact Lists for Customer cascadedsdev</title>
  <author />
  <updated>2012-10-29</updated>
  <content type="application/vnd.ctct+xml">
    <ContactList xmlns="http://ws.constantcontact.com/ns/1.0/">
      <OptInDefault>true</OptInDefault>
      <Name>My New List</Name>
      <SortOrder>0</SortOrder>
    </ContactList>
  </content>
</entry>

I've reviewed the post that talks about the 415 error but I'm at a loss as to what the problem might be.  Everything looks correct

I would greatly appreciate any assistance.

Regards,

Chris

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Advisor

Re: 415 Error When Adding a New List in VB.Net

Thank you Shannon, that's exactly the problem.

 

View solution in original post

2 REPLIES 2
Highlighted
Employee

Re: 415 Error When Adding a New List in VB.Net

Hi Chris,

 

It looks like the issue is that you're setting the wrong content type to add a contact list.  You want to set your Content type to "application/atom+xml".

 

I hope that helps!

 

Best Regards,

Shannon W.

API Support Specialist.

Highlighted
Advisor

Re: 415 Error When Adding a New List in VB.Net

Thank you Shannon, that's exactly the problem.

 

View solution in original post

Developer Portal

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

Visit Page

Register for our "Making Sense of Online Marketing for Retail" Webinar

Join us on Thursday, August 13th at 2pm ET for a free webinar where we'll discuss how to incorporate online marketing into your retail store.

Read More
Featured