Skip to main content

How to increase the member list pagination limit beyond the default 50?

hi guys. here it says default is 50 but doesnt name the maximum. what is it ? 💓

13 comments

  • Tyler Bell
    Tyler Bell

    Max is 100.

    0
  • TheStyle134 null
    TheStyle134 null OP

    is it possible to ask for more?

    0
  • Tyler Bell
    Tyler Bell

    Beyond 100, you’ll need to paginate.
    Where are you using the api?

    I can give you example code.

    0
  • TheStyle134 null
    TheStyle134 null OP

    google cloud console, tho. i'd appreciate!

    0
  • Tyler Bell
    Tyler Bell

    What language?

    0
  • TheStyle134 null
    TheStyle134 null OP

    node js

    0
  • Tyler Bell
    Tyler Bell

    Sweet.

    Yeah I’ll send you some code.

    can you use NPM packages in your project?

    We have a NPM package that makes using our API easier.

    0
  • TheStyle134 null
    TheStyle134 null OP

    im not using webflow, but a more limiting cms. that s why i am using gcf.

    so no, i can not use npms

    0
  • Tyler Bell
    Tyler Bell

    do you know what version of node you are using?

    const API_KEY = //your MS secret key; const BASE_URL = 'https://admin.memberstack.com/members'; async function fetchMembers(url, headers) { try { const response = await fetch(url, { headers }); if (!response.ok) { throw new Error(`Error: ${response.status}`); } return await response.json(); } catch (error) { console.error('Failed to fetch members:', error); return null; } } async function listAllMembers(after = null, order = 'ASC', limit = 50) { const url = new URL(BASE_URL); if (after) url.searchParams.append('after', after); url.searchParams.append('order', order); url.searchParams.append('limit', limit); const headers = { 'X-API-KEY': API_KEY }; const membersData = await fetchMembers(url, headers); if (membersData && membersData.hasNextPage) { const nextMembers = await listAllMembers(membersData.endCursor, order, limit); return membersData.data.concat(nextMembers); } else { return membersData ? membersData.data : []; } } // Usage listAllMembers().then(members => { console.log('Total Members Fetched:', members.length); console.log('Members:', members); });
    the code above assumes you are using node v18 or higher.
     
     
     
    0
  • TheStyle134 null
    TheStyle134 null OP

    thankies!

    0
  • Peter McGrath
    Peter McGrath

    any way to get the list members limit above 100?

    Actions
    List Members
    Get a paginated list of members:

    Copy
    const url = 'https://admin.memberstack.com/members';
    axios.get(url, {headers}).then(res => {
    console.log(res.data);
    });

    Optional parameters:
    after - Pagination cursor
    order - ASC or DESC
    limit - Max number to return (default 50)

    or order by date_created ?

    0
  • A J
    A J

    Hey Peter McGrath, I believe currently we can make use of the cursor to find the next set of members after limit is reached, however I think it is possible to order the set of results by date_created as well.

    I just checked this by making an api call to get the list of members and added order=DESC as query parameter, and it seems to give me results in descending order based on the creation date and vice versa happens when I pass ASC as the order.

    Let me know if this helps.

    0
  • Manuel Ogomigo
    Manuel Ogomigo

    the limit is 100, did this for a project, the only way to get above 100, is to send request async, and get the endcursor to add the after param dynamically till there's no endcursor, making it the end of the list.

    here's a sample script I used for a recent project

    <script> const statusDiv = document.getElementById('status'); const startButton = document.getElementById('startButton'); startButton.onclick = function() { this.disabled = true; // Disable button to prevent multiple triggers fetchMembers('/members'); }; function fetchMembers(url) { fetch(url, { headers: { 'Accept': 'text/plain' } }) .then(response => response.text()) .then(data => { // Append the result to the status div statusDiv.innerHTML += \`\${data}</p>\`; // Extract next batch URL from the data const nextBatchMatch = data; console.log(nextBatchMatch); if (nextBatchMatch && nextBatchMatch[1]) { // Continue fetching the next batch fetchMembers(\`/members?after=\${data}\`); } else { statusDiv.innerHTML += '<p>All data has been fetched.</p>'; startButton.disabled = false; } }) .catch(error => { statusDiv.innerHTML += \`<p>Error fetching data: \${error}</p>\`; startButton.disabled = false; }); } </script>
    0

Please sign in to leave a comment.

Sitemap