// using the Syndication stuff provided in .NET 3.5
using System.ServiceModel.Syndication;
private String baseUri = "http://api.constantcontact.com/ws/customers/" + + "/";
private List allContacts = new List<SyndicationItem>();
private List allContactsDocs = new List<XmlDocument>();
private void refreshContacts()
{
allContacts.Clear();
SyndicationFeed contactsFeed = null;
try
{
contactsFeed = getFeed(baseUri + "contacts");
}
catch (WebException we)
{
throw we;
}
foreach (SyndicationItem si in contactsFeed.Items)
{
allContacts.Add(si);
allContactsDocs.Add(getXmlFeed(si.Id));
}
bool hasMore = false;
SyndicationLink nextLink = null;
foreach (SyndicationLink sl in contactsFeed.Links)
{
if (sl.RelationshipType == "next")
{
hasMore = true;
nextLink = sl;
break;
}
}
List visited = new List();
while (hasMore)
{
SyndicationFeed nextFeed = null;
try
{
nextFeed = getFeed("http://api.constantcontact.com" + nextLink.Uri.ToString());
}
catch (WebException we)
{
throw we;
}
foreach (SyndicationItem si in nextFeed.Items)
{
allContacts.Add(si);
allContactsDocs.Add(getXmlFeed(si.Id));
}
visited.Add(nextLink.Uri.ToString());
hasMore = false;
foreach (SyndicationLink sl in nextFeed.Links)
{
if (sl.RelationshipType == "next")
{
if (!visited.Contains(sl.Uri.ToString()))
{
hasMore = true;
nextLink = sl;
break;
}
}
}
}
}
private SyndicationFeed getFeed(String uriPath)
{
HttpWebRequest hwr = WebRequest.Create(uriPath) as HttpWebRequest;
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(baseUri), "Digest", new NetworkCredential(API_KEY + "%" + this.Uid, this.Pw));
hwr.Credentials = myCache;
HttpWebResponse resp = null;
try
{
resp = hwr.GetResponse() as HttpWebResponse;
}
catch (WebException we)
{
throw we;
}
SyndicationFeed sf = SyndicationFeed.Load(System.Xml.XmlReader.Create(resp.GetResponseStream()));
resp.Close();
return sf;
}
private XmlDocument getXmlFeed(String uriPath)
{
HttpWebRequest hwr = WebRequest.Create(uriPath) as HttpWebRequest;
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(baseUri), "Digest", new NetworkCredential(API_KEY + "%" + this.Uid, this.Pw));
hwr.Credentials = myCache;
HttpWebResponse resp = null;
try
{
resp = hwr.GetResponse() as HttpWebResponse;
}
catch (WebException we)
{
throw we;
}
XmlDocument doc = new XmlDocument();
doc.Load(System.Xml.XmlReader.Create(resp.GetResponseStream()));
resp.Close();
return doc;
}
Hi klouf,
Did you ever find a solution for this issue, I'm currently dealing with the same problem.
5 years later and this bug still exists. Can I assume it won't be fixed in API v1?
I wouldn't hold my breath. I can't even get them to fix API v2.
Thanks for pointing this out. The issue reported in 2008 was resolved. However, we have confirmed that is definitely an issue with pagination affecting some of our API customers (regardless of the version of the API) which results in pagnination looping. We have engineers looking it now, no immediate update as to cause or expected time to fix. We are treating this as a critical blocking defect with the API and have multiple people looking at getting a solution hot fixed to production as soon as we can.
In that case, sorry for the saucy post and thanks for the update :-)
Not a problem, I understand how frustrating this can be. Expectation is that pagination works and when it stops and goes into a loop like this, would be very hard to detect that and could cause integrations to go crazy.
We do have good news. On further investigation from the team, our v2 API is paginating correctly (pagination next links for v2 look surprisingly similar due to hashing, was a user error thinking they were the same when off by one character). We are looking into the way the v1 API hashes pagination values to see why we're getting stuck in a loop now. Hopefully will have another update soon.