We are trying to link a contact form on our website to a contact list in our Constant Contact account. We are utilizing the C# library to accomplish this.
After the form is submitted, this is called:
addContact(txtEmail.Text.Trim(), txtName.Text.Trim());
Method below:
Solved! Go to Solution.
Hi Kate,
You can retrieve all of your lists by performing a GET on https://api.constantcontact.com/ws/customers/{username}/lists. This will return up to 50 lists that are in your account, and a link to the next set of 50 if one exists. You can find more information on this at Retrieving a Contact List Collection.
As far as the C#.NET Library goes, this can be done by:
I hope that this helps. Please let us know if you have any other questions regarding this. Thanks!
David J
Ok, so an update. I believe it has to do with not being able to get the exact ID of the list. Is there anyway to grab the ID of the lists in Constant Contact? I haven't been able to find a way.
I found this out by trying:
The first one prints out with the name I gave it, however, the ID does not print out at all, which makes me believe it isn't being set properly.
So I have confirmed that the list is the issue. I tried adding a contact using this:
contactOptInList.ContactList = new ContactList("1");
And it was added to my default list. I need to know which ID my lists are so I can add them to the correct list. Is there anyway to find out the ID of all my lists?
Hi Kate,
You can retrieve all of your lists by performing a GET on https://api.constantcontact.com/ws/customers/{username}/lists. This will return up to 50 lists that are in your account, and a link to the next set of 50 if one exists. You can find more information on this at Retrieving a Contact List Collection.
As far as the C#.NET Library goes, this can be done by:
I hope that this helps. Please let us know if you have any other questions regarding this. Thanks!
David J
Hi David,
Thank you very much for replying. I appreciate it. I was able to use the C#.NET Library to display the list IDs so I now have this working correctly. Thank you for your assistance.
Hi David,
What if we want to show more than 50 lists?
Thanks
Hi EytanD,
GetUserContactListCollection can be used to pull more than 50 lists as well utilizing the out variable and passing it back into the function.
In the above example you used to get the first 50:
IList<ContactList> lists = Utility.GetUserContactListCollection(authdata, out nextChunk);
nextChunk will contain the URI for Lists greater than 50. To get those Lists:
IList<ContactList> lists = Utility.GetUserContactListCollection(authdata, out nextChunk); IList<ContactList> lists2 = Utility.GetUserContactListCollection(authdata, nextChunk, out anotherNextChunk);
Help this helps,
To clarify a little on Andres post, nextChunk will be NULL if there are no additional lists to pull back. So, you can run a simple loop to pull all the lists down. Keep in mind, if you're talking 1000s of lists (however unlikely), this could take a few seconds and you may want to put in a progress bar or notification method in place to let the user know that you're still pulling new lists:
String nextChunk, currentChunk = string.Empty; List<ContactList> lists = new List<ContactList>();
do { lists.AddRange((List<ContactList>)Utility.GetUserContactListCollection(authdata, currentChunk, out nextChunk)); currentChunk = nextChunk; } while (nextChunk != string.Empty);
Thanks Dave and Andrew :smileyhappy:.
One more question what if I want to add a contact by providing name of the list instead of List Id
like in the example below.
ContactOptInList contactOptInList = new ContactOptInList();
Thanks.
The constructor for ContactList which accepts a name and the OptInDefault value (true/false) is only intended to be used when creating a new list. Whenever you need to use a list within a Contact action or a Campaign action, you will need to provide a ContactList object that has the ID set. You can either permanently store the List ID on your side once you choose the list you want or you can continue to use the API to pull the list(s) in question on demand using the method above.
Unfortunately, there is no option for looking up a list by name currently. We will update if this feature is released in the future.
..but you could build your own GetListByName() method using a linq query...
IList <ContactList> coll = Utility.GetUserContactListCollection(authdata, out nextChunk);
ContactList match = (from list in coll
.Where(l => l.Name == groupName)
select list).FirstOrDefault();
The string variable, "groupName" is the List key for the look-up. This will return a List object so you can all the properties from the object (Id, ShortName, Link, OptInDefault, SortOrder, etc.)
I am not sure about GetUserContactListCollection, but I do know that I had to modify Utility.cs.
getListMembers(string link, AuthenticationData Authdata, outstring nextChunk) to the following in order to get a loop to work properly...
public static IList<Contact> getListMembers(string link, AuthenticationData Authdata, out string nextChunk)
{
if (string.IsNullOrEmpty(link))
{
throw new ArgumentException("list link cannot be null or empty", "link");
}
//Create new xmldocument, create memberslist uri, GET, load XML.
XmlDocument xDoc = new XmlDocument();
//If initial chunk, append /members to URI, if next link, no need to append /members, use link as is.
string membersURI;
if (link.Contains("next") == true)
{
//my modification to the code...
membersURI = "https://api.constantcontact.com" + link;
//original code...
//membersURI = link;
}
else
{
membersURI = "https://api.constantcontact.com" + link + "/members";
}
...
}
The holidays have come and gone. For many seasonal businesses, this means the rush of shoppers has decreased as well. Instead of turning off the lights and waiting for spring, make your email marketi...
See Article