We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Trouble with adding a contact list

Occasional Participant

Trouble with adding a contact list

I am trying to add a list to a contact using VBA with MSAccess (& XMLHTTP):


1.) I first do a GET for a contact and use the Getobj.response.xml to add the list reference


2.) I create a node (nNode) pointing to the /entry/content/Contact/ContactLists


3.) I create a string for a new element:

<ContactList id="http://api.constantcontact.com/ws/customers/[removed for security]/lists/8 >

Here is the code I used to add the child node (which seems to work)

xmlstr = "<ContactList id=""http://api.constantcontact.com/ws/customers/" & MyUserName & "/lists/" & Format(SRA_List(i).URI) & " >" & vbCrLf _
                    & "<OptInSource>ACTION_BY_CUSTOMER</OptInSource>" & cbCRLF _
                    & "</ContactList>"

                Set elem = xmlDoc.createElement("ContactList")
                elem.Text = xmlstr
                Set Pelem = nNode
                Pelem.appendChild elem

 The section of the body (which has now been modified) used in the PUT:

                <ContactList id="http://api.constantcontact.com/ws/customers/[removed for security]/lists/3">
                    <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/randyneilson/lists/3" rel="self"></link>
                <ContactList id="http://api.constantcontact.com/ws/customers/[removed for security]/lists/7">
                    <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/randyneilson/lists/7" rel="self"></link>
                <ContactList xmlns="">&lt;ContactList id="http://api.constantcontact.com/ws/customers/[removed for security]/lists/8 &gt;


4.) Although this doesn't look pretty, the put is successful with a status of 204 - No Content. However when I do a GET of that contact, the new list is not added.


So I must be doing something wrong with adding the XML node for the new contactlist.


Any suggestions? or ideas?





When you're adding lists to a contact, it's important to follow the given format for adding a list. There are a few things happening here when your code is run:


1. Your xmlStr that you are adding as text is being encoded with entities and is being simply added as text rather than XML code. Most likely you would need to create new XML elements for each piece, or there may be a field that you can set which won't change characters such as '<' and '>' to their HTML entity equivalents.

2. Your XML has two <ContactList> elements where only one is needed. See below for an example of the given format vs. what you have created:

Given Format:
<ContactList id="http://api.constantcontact.com/ws/customers/joesflowers/lists/1" />

Your Format:
<ContactList xmlns="">
<ContactList id="http://api.constantcontact.com/ws/customers/randyneilson/lists/8 >


If you can modify what you have to create the correct XML, you should see the new list created successfully.



Elijah G.

Tier 2 Support


Elijah G.
API Support Engineer
Developer Portal

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

Visit Page