Parameters limit on paginated list of members Answered

Post author
TheStyle134 null

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

Comments

13 comments

  • Comment author
    Tyler Bell

    Max is 100.

    0
  • Comment author
    TheStyle134 null

    is it possible to ask for more?

    0
  • Comment author
    Tyler Bell

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

    I can give you example code.

    0
  • Comment author
    TheStyle134 null

    google cloud console, tho. i'd appreciate!

    0
  • Comment author
    Tyler Bell

    What language?

    0
  • Comment author
    TheStyle134 null

    node js

    0
  • Comment author
    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
  • Comment author
    TheStyle134 null

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

    so no, i can not use npms

    0
  • Comment author
    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
  • Comment author
    TheStyle134 null

    thankies!

    0
  • Comment author
    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
  • Comment author
    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
  • Comment author
    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.