I've been using the following code for months. I updated C# api v2 codebase on 11/11/2013. I can only get 146 campaigns for the year for our account when I know we have more. In fact, I can't get any Campaign data more recent than October 7th, 2013 even when I move the start date. Any clue why this would be happening?
var campaigns = _cc.GetCampaigns(CampaignStatus.SENT, new DateTime(2013, 1, 1)); var pagination = campaigns.Meta.Pagination; List<EmailCampaign> allCampaigns = new List<EmailCampaign>(); // if there are more then 50 results, pagination.Next is populated // with the next URL to fetch while (pagination.Next != null) { log.Info(DateTime.Now + ": APIv2.GetEmailCampaigns Pagination Next " + pagination.Next); // Avoid the API limiting Thread.Sleep(1000); campaigns = _cc.GetCampaigns(pagination); pagination = campaigns.Meta.Pagination; allCampaigns.AddRange(campaigns.Results); }
I think I figured out the problem. I think the sort order for campaigns returned has flipped recently? I could swear the Campaigns were returned in chronological order previously and now they are returned in reverse chrono. My posted code snippet was missing a line too. My code looks like this:
var campaigns = _cc.GetCampaigns(CampaignStatus.SENT, new DateTime(2013, 1, 1)); var pagination = campaigns.Meta.Pagination; List<EmailCampaign> allCampaigns = new List<EmailCampaign>(); allCampaigns.AddRange(campaigns.Results); // if there are more then 50 results, pagination.Next is populated // with the next URL to fetch while (pagination.Next != null) { log.Info(DateTime.Now + ": APIv2.GetEmailCampaigns Pagination Next " + pagination.Next); // Avoid the API limiting Thread.Sleep(1000); campaigns = _cc.GetCampaigns(pagination); pagination = campaigns.Meta.Pagination; allCampaigns.AddRange(campaigns.Results); }
Hello,
Thanks for posting on the forums. The GetCampaigns method currently returns the campaigns in reverse chronological order, so you would get the "newest" campaigns first. Your code looks fine. Have you been able to been able to sort out what happened with your results?
Regards,
Andrew B.
Constant Contact, API Support
I guess my situation is fixed. the only thing I can think of is that there might have been a blip with the API returning less than full results earlier today. Also, like I mentioned, I've had to sort my list which I didn't need to do before. But other than that, I'm set. Thx.
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