cancel
Showing results for 
Search instead for 
Did you mean: 

Determining Max Contact Count for Pagination

Highlighted
Valued Developer

Determining Max Contact Count for Pagination

When paging through arrays of Contacts via the v2 API, the pagination next_page value is returned even when there is not another page. Is this a bug, or is there a logical reason for that?

 

I ask because it's very difficult to determine if you've reached the end of the list. It seems silly to make a separate call to retrieve a Contact List just so that you can get the contact_count value. And it's not possible (to my knowledge) to get a contact_count value for OPTOUT or REMOVED lists.

 

Any thoughts on this?

4 REPLIES 4
Honored Contributor

Re: Determining Max Contact Count for Pagination

Hello,

 

I have been looking into the behavior you've described and I was not able to reproduce what you've described. Here is an example of the second (and final) page for a list of contacts in my account:

{
    "meta": {
        "pagination": {}
    },
    "results": [
        {
		// Contact
	},
        {
		// Contact
	},
        {
		// Contact
	},
        {
		// Contact
	},
        {
		// Contact
	},
        {
		// Contact
	}
    ]
}

 

In this JSON response from the API, you will notice that the pagination object is empty, which provides an easy way to determine if there is indeed a next page. With this ability to detect the final page from the lack of a next_link element, that should provide a simple way to know when you're done paging.

 

If your experience does not match this, it would be a great help if you could provide a short snippet of your code that demonstrates how you are handling paginated data. With that sample, I should be able to provide some insight/advice on how you can accomplish your goal without having to get the details for the list every time.

 

Please let me know if you have any questions as well!

 

Sincerely

Elijah G.
API Support Engineer
Valued Developer

Re: Determining Max Contact Count for Pagination

Thanks for your response. After your reply I was able to find the issue with my code that was persisting the next_page value instead of clearing it when the JSON value came back empty. That is no longer an issue.

 

I do still have an issue finding a count total for contacts when searching by status. In order to provide a page count, it's necessary to know the total number of contacts. I can't find a way to accomplish this when querying the contacts API. Is there a way to return totals for statuses, such as OPTOUT, REMOVED, or ACTIVE?

Valued Developer

Re: Determining Max Contact Count for Pagination

No one has ideas for how to return a count total for contacts when searching by status?

Moderator

Re: Determining Max Contact Count for Pagination

Today it isn't possible to get that information through the API.  It's a great feature request and we'll put it in the backlog to add it to a future version of the API.  I'll have the team look into seeing if we can add it to the v2 API but I'm not if it will be possible for us to do that.

Dave Berard
Senior Product Manager, Constant Contact