How to fetch all member data from Memberstack using JavaScript? Answered
Hey,
Is there a way / javascript code to get all members in memberstack?
I need to fetch a list from memberstack that lists them, this is the code I have now:
const apiKey = 'jouw_memberstack_api_key';
const endpoint = 'https://api.memberstack.com/v1/members';
async function fetchMembers() {
try {
const response = await fetch(endpoint, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization':Bearer ${apiKey}
}
});if (!response.ok) { throw new Error('Netwerkresponse was niet ok.'); } const members = await response.json(); console.log(members);
} catch (error) {
console.error('Er was een probleem met het ophalen van de members:', error);
}
}
// Roep de functie aan om de members te fetchen
fetchMembers();
But I'm running into CORS issues.
I'm using Webflow
Is there a way for me to list all members in a different way?
I know there is the getCurrentMember method, is there an getAllMembers-equivalent?
Comments
3 comments
While I don't know much about the use-case you are trying to solve, there is an action to list all members via Admin API.
However, you might also explore options like Make / Zapier to have a sync between Memberstack and Webflow collections for populating users, so that all of this is handled via back-end instead of client-side code.
Thanks,
The problem I'm facing is that I'm using Webflow and I don't really wanne put my secret keys in there
But if that's the only way, I shall look for an other option
Never use the admin api in the frontend 🚨. If you do, anyone can have access to your member's personal information and also have access to modify your user base.
You can export your members in the dashboard and import them in a different platform like Webflow CMS, Airtable, etc and pull the data from there. If you were to use the admin api you would have to call it behind a server to protect your Memberstack secret information and your user's.
Then you can use AJ's solution to sync your member's data using Zapier/Make or your own server to always pull the latest information. Or you can manually re import the data periodically.
Please sign in to leave a comment.