Most methods that return lists support pagination using two different strategies depending on the specific API endpoint.
1. Using limit and page (Most common)
Used by methods like mg.domains.domainTags.list(), mg.events.get(), mg.lists.list(), mg.lists.members.listMembers(), mg.validate.list(), and mg.suppressions.list().
To paginate, include a limit in your initial query. The response will contain a pages object containing navigation links (first, last, next, previous). To fetch the next set of results, take the string value from the page property of the desired navigation object and pass it as the page argument in your next call.
2. Using limit and skip
Used by methods like mg.domains.list(), mg.domains.domainCredentials.list(), mg.routes.list(), and mg.webhooks.list().
To paginate, provide skip (number of records to bypass from the start) and limit (number of records to receive) in the query object.
// Strategy 1: limit and page
// first call
const listMembers = await mg.lists.members.listMembers('your_mailing_list', { limit: 2 });
// second call using the 'page' string from the previous response
const nextMembers = await mg.lists.members.listMembers('your_mailing_list', {
limit: 2,
page: '?page=next&address=test-1%40example.com&limit=2'
});
// Strategy 2: limit and skip
const listDomainCredentials = await client.domains.domainCredentials.list(
'your_domain_name',
{
skip: 10,
limit: 1
}
);