Member Actions
The Admin Package provides powerful methods to manage members through your server-side code. This section covers the complete set of member management capabilities, including listing, creating, updating, and deleting members.
- Make sure you’ve initialized the Admin Package with your secret key as shown in the Quick Start guide
- Consider using test mode (sandbox) for development and testing
- Be aware of API rate limits (25 requests per second).
- If you are hitting this limit, consider caching responses
List All Members
Retrieve a paginated list of members in your application.
The members.list() method allows you to fetch members with pagination support:
// Basic usage
const members = await memberstack.members.list();
// With pagination and ordering
const members = await memberstack.members.list({
after: 2458433, // Start after this cursor
limit: 5, // Return max 5 members
order: "DESC" // Descending order (newest first)
});Response Structure:
For applications with large member bases, implement pagination best practices:
- Use the
limitparameter to control response size. The default is 50 and the max is 100 - Store the
endCursorvalue to continue paginating from where you left off - Check
hasNextPageto determine if more members exist
Retrieve a Member
Get detailed information about a specific member by ID.
To fetch a single member by ID, use the members.retrieve() method:
const member = await memberstack.members.retrieve({
id: "mem_abc123"
});Response:
The response contains the complete member data:
status is one of ACTIVE, TRIALING, REQUIRES_PAYMENT, REQUIRES_AUTHENTICATION or CANCELED. There is no PAST_DUE: a Stripe subscription that is past_due or unpaid shows as REQUIRES_PAYMENT. Only ACTIVE and TRIALING grant the plan’s access.
Don’t gate on active. In the Admin API it reflects whether the latest payment went through, not whether the member has access; in the browser SDK it is true only for ACTIVE, so trialing members show false. Check status instead.
A subscription set to cancel at the end of the billing period stays ACTIVE, with payment.cancelAtDate (Unix seconds) set, until it ends; then it becomes CANCELED. See Plan Connection Status for the full table.
retrieve() does not throw when no member matches: it resolves { data: null }. Check for null; catch only sees other failures. API errors reject with a plain { code, message } object (no HTTP status). A rate-limited call (HTTP 429), or any other response that is not JSON, rejects with a plain string such as Too many requests, please try again later. A request that never got a response rejects with a network Error:
try {
const { data: member } = await memberstack.members.retrieve({
id: "mem_abc123"
});
if (!member) {
// Resolves { data: null }: a missing member is not an error
console.error("Member not found");
} else {
// Process member data
console.log(member);
}
} catch (error) {
if (typeof error === "string") {
// Rate limit (429) or another non-JSON response: the rejection is the text itself
console.error(`API error: ${error}`);
} else {
// API errors reject with { code, message }; a network failure is an Error
console.error(`API error: ${error.code} ${error.message}`);
}
}Create a Member
Programmatically create new members in your application.
The members.create() method allows you to create new members with custom data and optional plan connections:
const newMember = await memberstack.members.create({
email: "jane@example.com",
password: "SecurePassword123",
plans: [
{
"planId": "pln_abc123"
}
],
// Keys must match your custom field keys exactly (see the dashboard).
// On create, keys that are not defined custom fields are silently dropped.
customFields: {
"first-name": "Jane",
"last-name": "Smith"
},
metaData: {
source: "Admin API"
},
json: {
preferences: {
newsletter: true,
darkMode: false
}
},
loginRedirect: "/dashboard"
});- Required:
email- The member's email addresspassword- The member's password
- Optional:
plans- Array of plan objects to connectcustomFields- Object containing custom data fieldsmetaData- Object for internal metadatajson- Object for complex JSON dataloginRedirect- URL to redirect after login
When creating members programmatically:
- Always use strong passwords or implement passwordless options
- Consider notifying members that their account has been created
- For paid plans, use the DOM package’s checkout flow instead
Update a Member
Modify existing member information using the Admin API.
Use the members.update() method to modify a member’s information. Only the fields you include will be updated:
const updatedMember = await memberstack.members.update({
id: "mem_abc123",
data: {
// Update email: this marks the member unverified, and if email verification
// is enabled for your app a verification email is sent to the new address
email: "jane.updated@example.com",
// Update custom fields
customFields: {
"first-name": "Jane",
"last-name": "Johnson",
country: "Canada"
},
// Update metadata
metaData: {
lastUpdated: new Date().toISOString()
},
// Update JSON data
json: {
preferences: {
newsletter: false,
darkMode: true
}
},
// Update login redirect
loginRedirect: "/new-dashboard"
}
});Tips for updating members:
- Only include the fields you want to change
- To clear a custom field, set it to
null. The key stays on the member with the valuenull; it is not removed - Use each custom field's exact key as shown in your Memberstack dashboard under Members → Custom Fields (typically kebab-case such as
first-name, notfirstName).create()silently ignores keys that are not defined custom fields;update()stores whatever keys you send. - Consider implementing validation before updates
- Changing
emailsets the member'sverifiedback tofalse. If your app has email verification enabled, Memberstack also sends a verification link to the new address (subject to the normal sending limits); if it is disabled, nothing is sent. Sendingverified: truein the samedataobject keeps the member verified, but does not stop that email
Delete a Member
Permanently remove a member from your application.
To delete a member, use the members.delete() method:
const result = await memberstack.members.delete({
id: "mem_abc123"
});
// Result contains the deleted member ID
console.log(`Deleted member: ${result.data.id}`);Warning: Deleting a member is permanent and cannot be undone. Consider these precautions:
- Implement confirmation steps before deletion
- Backup important member data if needed
- Consider using a "deactivated" flag instead of full deletion
- Handle any dependent resources in your application
Add a Free Plan to a Member
Give a member access to a free plan programmatically.
To add a free plan to an existing member:
await memberstack.members.addFreePlan({
id: "mem_abc123",
data: {
planId: "pln_free_plan"
}
});- This method only works with free plans (plans with no prices). Passing a paid plan rejects with code
plan-not-free - For paid plans, use the DOM package’s checkout flow
- Members can have multiple plans simultaneously
Remove a Free Plan from a Member
Revoke access to a free plan programmatically.
To remove a free plan from a member:
await memberstack.members.removeFreePlan({
id: "mem_abc123",
data: {
planId: "pln_free_plan"
}
});When removing plans:
- Consider notifying the member about plan changes
- Handle any access control logic in your application
- Update any relevant user interfaces to reflect plan status