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.

415 Error on contact update

Highlighted
Occasional Contributor

415 Error on contact update

Greetings all.  I'm having some trouble updating contacts via API.  When I try and PUT the XML to the server, I get a 415 error common atom fields missing. Here's the XML i'm attempting to send.  All I did was get this file from the server, inserted one value in CustomField1, and change the content type to application/atom+xml.   Other than that, the file is identical to the one from the server, so I'm not sure what's missing.  Any thoughts??

 

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/username/contacts/2616" rel="edit"></link>
  <id>http://api.constantcontact.com/ws/customers/username/contacts/2616</id>
  <title type="text">Contact: name@gmail.com</title>
  <updated>2012-12-28T14:40:24.375Z</updated>
  <author>
    <name>Constant Contact</name>
  </author>
  <content type="application/atom+xml">
    <Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/username/contacts/2616">
      <Status>Active</Status>
      <EmailAddress>name@gmail.com</EmailAddress>
      <EmailType>HTML</EmailType>
      <Name>name name</Name>
      <FirstName>name</FirstName>
      <MiddleName></MiddleName>
      <LastName>name</LastName>
      <JobTitle></JobTitle>
      <CompanyName></CompanyName>
      <HomePhone></HomePhone>
      <WorkPhone></WorkPhone>
      <Addr1></Addr1>
      <Addr2></Addr2>
      <Addr3></Addr3>
      <City></City>
      <StateCode></StateCode>
      <StateName></StateName>
      <CountryCode></CountryCode>
      <CountryName></CountryName>
      <PostalCode></PostalCode>
      <SubPostalCode></SubPostalCode>
      <Note></Note>
      <CustomField1>1234567890</CustomField1>
      <CustomField2></CustomField2>
      <CustomField3></CustomField3>
      <CustomField4></CustomField4>
      <CustomField5></CustomField5>
      <CustomField6></CustomField6>
      <CustomField7></CustomField7>
      <CustomField8></CustomField8>
      <CustomField9></CustomField9>
      <CustomField10></CustomField10>
      <CustomField11></CustomField11>
      <CustomField12></CustomField12>
      <CustomField13></CustomField13>
      <CustomField14></CustomField14>
      <CustomField15></CustomField15>
      <ContactLists>
        <ContactList id="http://api.constantcontact.com/ws/customers/username/lists/4">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/username/lists/4" rel="self"></link>
          <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
          <OptInTime>2012-12-20T21:35:27.758Z</OptInTime>
        </ContactList>
      </ContactLists>
      <Confirmed>true</Confirmed>
      <InsertTime>2012-12-20T21:35:27.492Z</InsertTime>
      <LastUpdateTime>2012-12-28T14:40:24.375Z</LastUpdateTime>
    </Contact>
  </content>
  <source>
    <id>http://api.constantcontact.com/ws/customers/username/contacts</id>
    <title type="text">Contacts for Customer: username</title>
    <link href="contacts"></link>
    <link href="contacts" rel="self"></link>
    <author>
      <name>username</name>
    </author>
    <updated>2012-12-28T15:17:21.145Z</updated>
  </source>
</entry>

 Thanks,

 

-Doug

9 REPLIES 9
Highlighted
Honored Contributor

Re: 415 Error on contact update

Hello Doug,

I have reviewed the XML that you pasted and I found that there was an <OptInSource> tag pair missing from the <Contact> tags in your XML. This is because the OptInSource tag is required for the contact and the contact lists. I have placed an additional indent on the tag that I corrected so that you can see what I added for you.

 

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/username/contacts/2616" rel="edit"></link>
  <id>http://api.constantcontact.com/ws/customers/username/contacts/2616</id>
  <title type="text">Contact: name@gmail.com</title>
  <updated>2012-12-28T14:40:24.375Z</updated>
  <author>
    <name>Constant Contact</name>
  </author>
  <content type="application/atom+xml">
    <Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/username/contacts/2616">
	        <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
      <Status>Active</Status>
      <EmailAddress>name@gmail.com</EmailAddress>
      <EmailType>HTML</EmailType>
      <Name>name name</Name>
      <FirstName>name</FirstName>
      <MiddleName></MiddleName>
      <LastName>name</LastName>
      <JobTitle></JobTitle>
      <CompanyName></CompanyName>
      <HomePhone></HomePhone>
      <WorkPhone></WorkPhone>
      <Addr1></Addr1>
      <Addr2></Addr2>
      <Addr3></Addr3>
      <City></City>
      <StateCode></StateCode>
      <StateName></StateName>
      <CountryCode></CountryCode>
      <CountryName></CountryName>
      <PostalCode></PostalCode>
      <SubPostalCode></SubPostalCode>
      <Note></Note>
      <CustomField1>1234567890</CustomField1>
      <CustomField2></CustomField2>
      <CustomField3></CustomField3>
      <CustomField4></CustomField4>
      <CustomField5></CustomField5>
      <CustomField6></CustomField6>
      <CustomField7></CustomField7>
      <CustomField8></CustomField8>
      <CustomField9></CustomField9>
      <CustomField10></CustomField10>
      <CustomField11></CustomField11>
      <CustomField12></CustomField12>
      <CustomField13></CustomField13>
      <CustomField14></CustomField14>
      <CustomField15></CustomField15>
      <ContactLists>
        <ContactList id="http://api.constantcontact.com/ws/customers/username/lists/4">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/username/lists/4" rel="self"></link>
          <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
          <OptInTime>2012-12-20T21:35:27.758Z</OptInTime>
        </ContactList>
      </ContactLists>
      <Confirmed>true</Confirmed>
      <InsertTime>2012-12-20T21:35:27.492Z</InsertTime>
      <LastUpdateTime>2012-12-28T14:40:24.375Z</LastUpdateTime>
    </Contact>
  </content>
  <source>
    <id>http://api.constantcontact.com/ws/customers/username/contacts</id>
    <title type="text">Contacts for Customer: username</title>
    <link href="contacts"></link>
    <link href="contacts" rel="self"></link>
    <author>
      <name>username</name>
    </author>
    <updated>2012-12-28T15:17:21.145Z</updated>
  </source>
</entry>

 

If you do experience further issues please reply to this topic with the error message you receive and we will be happy to help you.

 

Sincerely,

Elijah G.

Tier 2 Support

Elijah G.
API Support Engineer
Highlighted
Occasional Contributor

Re: 415 Error on contact update

It still did not work with the added opt in source.  same error 415 returned on send to the server.  Any other ideas?

 

-Doug

Highlighted
Moderator

Re: 415 Error on contact update

Hi Doug,

 

I noticed in your first post that you mentioned you had the Content-type header set correctly, but the only way I can replicate the same 415 error is if the header is not present. Would you be able to try the call out using RESTClient? If you're still getting the same error, please save the request/response archive (from the file menu), and send that file to us at webservices@constantcontact.com for a closer look.

Nick Galbraith
Support Engineer
Highlighted
Occasional Contributor

Re: 415 Error on contact update

Thanks for the response, Nick.

 

the code works just fine in RESTclient.  I have determined that it is an error on my end.  I'm using VBA (which I know CC's team does not usually support) to send an the xml file to the server.  I'm uncertain what the problem is, but its my fault.  Thank you for the help anyways.  Are there any examples out there of vba interfacing with CC's API?

 

-Doug

Highlighted
Moderator

Re: 415 Error on contact update

Hi Doug,

 

We won't be able to gaurantee a fix, but you're more than welcome to provide your code, and we can take a look. I'd suggest emailing it to us, for privacy reasons.

Nick Galbraith
Support Engineer
Highlighted
Occasional Participant

Re: 415 Error on contact update

I am having the same issue as Doug .... I to am using VBA in MSAccess. My test is to GET one contact then PUT the same information back.  When I use RESTclient, everything works.  However when I use the code, the GET works, but the PUT fails with error 415.  I suspect there is something wrong with the way I am using the DOM object or a missing header var.   I am running out of ideas so any help you can provide would be very welcome.

 

 

 Here is the code I am using:

---------------------------------------------------------------------------------------------------------- 

Function UpdateContact(ByVal URI As Long) As Boolean
Dim GetContactInfo As New XMLHTTP60
Dim PutContactInfo As New XMLHTTP60
Dim xmlDoc As New DOMDocument
Dim sID As String
Dim url As String

sID = Format(URI)
Call InitVars ' set: MyUserName, APIkey, MyPassowrd

   ' create the GET command
    url = "https://api.constantcontact.com/ws/customers/" & MyUserName & "/contacts/" & sID
    Set GetContactInfo = CreateObject("MSXML2.XMLHTTP")
    GetContactInfo.Open "GET", url, False, APIkey & MyUserName, MyPassword
    GetContactInfo.send
    If GetContactInfo.status < 400 Then
        ' Process the results
        Set xmlDoc = New MSXML2.DOMDocument60
        If Not xmlDoc.loadXML(GetContactInfo.responseText) Then
               Err.Raise xmlDoc.parseError.ErrorCode, , xmlDoc.parseError.reason
        End If

        ' create the PUT command
        Set PutContactInfo = CreateObject("MSXML2.XMLHTTP")
        PutContactInfo.Open "PUT", url, False, APIkey & MyUserName, MyPassword
        PutContactInfo.setRequestHeader "Content-Type", "application/atom+xml"
        PutContactInfo.send xmlDoc
        If PutContactInfo.status < 400 Then
                UpdateContact = True
        Else
                UpdateContact = False
         End If
     Else ' unsuccessful GET
           UpdateContact = False
     End If

' clean up
Set GetContactInfo = Nothing
Set PutContactInfo = Nothing
Set xmlDoc = Nothing

End Function

------------------------------------------------------------------

The status I receive from the PUT is: Error 415: The request contains errors in the common Atom sections, which lie outside <entry> or <Content>, such as <feed>, <id>, <author> or <updated>.

 

What am I doing wrong?  Does this mean the Content-Type is wrong?

 

For now I am PUTing the same information that I GET.  After I am able to get this working, I will add in the code to modifiy customfields in the contact record.

Highlighted
Honored Contributor

Re: 415 Error on contact update

Hello Randy,

 

I have looked over your code and it appears that the XML may be getting somewhat modified by the VBA DOM parser that is loading the XML. Is it possible to dump the XML that is being sent back to Constant Contact in a plaintext format? If so, could you post it here as a reply after removing any sensitive information (such as email address or Constant Contact username)?

 

The idea behind what you are doing should work correctly as the response XML from a specific contact can be used to PUT to the same URI. The error that you are seeing causes me to suspect that something is being added to the XML that is unwanted.

 

Also, a test you could try is to send the response text from the GET request unaltered as the payload for the PUT request.

 

If you do have additional questions, please feel free to post them as a reply!

 

Sincerely,

Elijah G.

Tier 2 Support

Elijah G.
API Support Engineer
Highlighted
Occasional Participant

Re: 415 Error on contact update

I have solved the problem by using ServerXMLHTTP60 instead of XMLHTTP60.  Now the put works.  thanks for the tips.

Highlighted
Honored Contributor

Re: 415 Error on contact update

Thanks for the confirmation, Randy!

 

Please let us know if you have any more questions and we will be happy to assist with them.

 

Sincerely,

Elijah G.

Tier 2 Support

Elijah G.
API 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
Featured