API v2 GetCampaigns method in C# stops returning data after a certain date

Highlighted
Occasional Advisor

API v2 GetCampaigns method in C# stops returning data after a certain date

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);

            }

 

3 REPLIES 3
Highlighted
Occasional Advisor

Re: API v2 GetCampaigns method in C# stops returning data after a certain date

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);
            }

 

Regular Advisor

Re: API v2 GetCampaigns method in C# stops returning data after a certain date

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

Highlighted
Occasional Advisor

Re: API v2 GetCampaigns method in C# stops returning data after a certain date

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.

Developer Portal

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