memberstack-admin-api
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMemberstack Admin API Skill
Memberstack Admin API 使用指南
This skill provides guidance for interacting with the Memberstack Admin API. It covers two core domains: Member management and Data Tables.
本指南提供了与Memberstack Admin API交互的操作指导,涵盖两大核心领域:成员管理和数据表。
Quick Start
快速开始
All requests require an API key passed via header:
x-api-key: YOUR_API_KEYBase URL:
https://admin.memberstack.comData Tables endpoints use the prefix; Member endpoints do not.
/v2/所有请求都需要通过请求头传递API key:
x-api-key: YOUR_API_KEYBase URL:
https://admin.memberstack.com数据表端点使用前缀;成员端点则不需要。
/v2/API Key Handling
API Key 处理
Never ask the user for their API key directly in the conversation. API keys are sensitive credentials and should never appear in chat, code snippets shown to the user, or be hardcoded in source files. Instead:
- Store the key in a file (e.g.,
.env) and read it viaMEMBERSTACK_API_KEY=sk_...(Node) orprocess.env.MEMBERSTACK_API_KEY(Python).os.environ["MEMBERSTACK_API_KEY"] - Alternatively, use the platform's secrets/environment variable management (e.g., Vercel Environment Variables, Cloudflare Secrets, AWS Secrets Manager).
- When generating code, always reference the key from an environment variable, never use a placeholder that looks like a real key.
- If the user pastes an API key in the chat, remind them to rotate it and move it to a file or secret store instead.
.env
切勿在对话中直接向用户索要其API key。API key是敏感凭证,绝不能出现在聊天内容、展示给用户的代码片段中,也不能硬编码到源文件中。应采取以下方式:
- 将密钥存储在文件中(例如
.env),并通过MEMBERSTACK_API_KEY=sk_...(Node.js)或process.env.MEMBERSTACK_API_KEY(Python)读取。os.environ["MEMBERSTACK_API_KEY"] - 或者使用平台的密钥/环境变量管理功能(例如Vercel环境变量、Cloudflare Secrets、AWS Secrets Manager)。
- 生成代码时,始终从环境变量中引用密钥,切勿使用看起来像真实密钥的占位符。
- 如果用户在聊天中粘贴了API key,提醒他们轮换密钥,并将其移至文件或密钥存储中。
.env
When to Read Reference Files
何时查阅参考文件
This skill bundles the full API reference docs. Read them based on what the user needs:
-
Member operations (list, get, create, update, delete, add/remove plans): Read
references/memberstack-member-actions.md -
Data Tables (list tables, get table schema, create/update/delete/query records): Read
references/memberstack-data-tables.md
If the task involves both members and data tables, read both files.
本指南包含完整的API参考文档。根据用户的需求查阅相应文档:
-
成员操作(列出、获取、创建、更新、删除、添加/移除套餐): 查阅
references/memberstack-member-actions.md -
数据表(列出表、获取表结构、创建/更新/删除/查询记录): 查阅
references/memberstack-data-tables.md
如果任务同时涉及成员和数据表,请查阅这两个文件。
API Overview
API 概览
Members API
成员API
Endpoints for managing members, their profiles, plan connections, and metadata.
| Action | Method | Endpoint |
|---|---|---|
| List members | GET | |
| Get member | GET | |
| Create member | POST | |
| Update member | PATCH | |
| Delete member | DELETE | |
| Add free plan | POST | |
| Remove free plan | POST | |
Key concepts:
- Member IDs start with , plan IDs with
mem_, connection IDs withpln_con_ - Members can be looked up by ID or URL-encoded email
- Pagination uses cursor-based +
after(max 200)limit - Members have ,
customFields,metaData,json, andpermissionsplanConnections
用于管理成员、其个人资料、套餐关联和元数据的端点。
| 操作 | 请求方法 | 端点 |
|---|---|---|
| 列出成员 | GET | |
| 获取成员 | GET | |
| 创建成员 | POST | |
| 更新成员 | PATCH | |
| 删除成员 | DELETE | |
| 添加免费套餐 | POST | |
| 移除免费套餐 | POST | |
核心概念:
- 成员ID以开头,套餐ID以
mem_开头,关联ID以pln_开头con_ - 可通过ID或URL编码的邮箱查找成员
- 分页使用基于游标(cursor)的+
after参数(最大值200)limit - 成员包含(自定义字段)、
customFields(元数据)、metaData、json(权限)和permissions(套餐关联)planConnections
Data Tables API
数据表API
Endpoints for managing structured data with typed fields, relationships, and querying.
| Action | Method | Endpoint |
|---|---|---|
| List tables | GET | |
| Get table | GET | |
| Create record | POST | |
| Update record | PUT | |
| Delete record | DELETE | |
| Query records | POST | |
Key concepts:
- Tables are referenced by key (e.g., ) or ID (e.g.,
products)tbl_... - Records hold data as key-value pairs matching field definitions
- Querying supports and
findManywith rich filtering (findUnique,equals,contains,gt,lt, logical operatorsin/AND/OR)NOT - Pagination via (max 100),
take, or cursor-basedskipafter - Field types include TEXT, NUMBER, DECIMAL, BOOLEAN, DATE, EMAIL, URL, REFERENCE, and MEMBER_REFERENCE variants
用于管理带类型字段、关联关系和查询功能的结构化数据的端点。
| 操作 | 请求方法 | 端点 |
|---|---|---|
| 列出数据表 | GET | |
| 获取数据表 | GET | |
| 创建记录 | POST | |
| 更新记录 | PUT | |
| 删除记录 | DELETE | |
| 查询记录 | POST | |
核心概念:
- 数据表可通过key(例如)或ID(例如
products)引用tbl_... - 记录以与字段定义匹配的键值对形式存储数据
- 查询支持和
findMany,并提供丰富的过滤条件(findUnique、equals、contains、gt、lt,以及逻辑运算符in/AND/OR)NOT - 分页可通过(最大值100)、
take或基于游标(cursor)的skip参数实现after - 字段类型包括TEXT、NUMBER、DECIMAL、BOOLEAN、DATE、EMAIL、URL、REFERENCE以及MEMBER_REFERENCE变体
Common Patterns
常见模式
Paginating Through All Members
遍历所有成员(分页)
javascript
let allMembers = [];
let cursor = undefined;
let hasMore = true;
while (hasMore) {
const params = new URLSearchParams({ limit: '200' });
if (cursor) params.set('after', cursor);
const res = await fetch(`https://admin.memberstack.com/members?${params}`, {
headers: { 'x-api-key': API_KEY }
});
const json = await res.json();
allMembers.push(...json.data);
hasMore = json.hasNextPage;
cursor = json.endCursor;
}javascript
let allMembers = [];
let cursor = undefined;
let hasMore = true;
while (hasMore) {
const params = new URLSearchParams({ limit: '200' });
if (cursor) params.set('after', cursor);
const res = await fetch(`https://admin.memberstack.com/members?${params}`, {
headers: { 'x-api-key': API_KEY }
});
const json = await res.json();
allMembers.push(...json.data);
hasMore = json.hasNextPage;
cursor = json.endCursor;
}Querying Data Records with Filters
带过滤条件的数据记录查询
javascript
const res = await fetch(
'https://admin.memberstack.com/v2/data-tables/products/records/query',
{
method: 'POST',
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: {
findMany: {
where: {
AND: [
{ price: { gte: 10 } },
{ inStock: { equals: true } }
]
},
orderBy: { price: 'asc' },
take: 50
}
}
})
}
);javascript
const res = await fetch(
'https://admin.memberstack.com/v2/data-tables/products/records/query',
{
method: 'POST',
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: {
findMany: {
where: {
AND: [
{ price: { gte: 10 } },
{ inStock: { equals: true } }
]
},
orderBy: { price: 'asc' },
take: 50
}
}
})
}
);Creating a Member with a Plan
创建关联套餐的成员
javascript
const res = await fetch('https://admin.memberstack.com/members', {
method: 'POST',
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'user@example.com',
password: 'securePassword123',
plans: [{ planId: 'pln_abc123' }],
customFields: { firstName: 'Jane', country: 'Australia' }
})
});javascript
const res = await fetch('https://admin.memberstack.com/members', {
method: 'POST',
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'user@example.com',
password: 'securePassword123',
plans: [{ planId: 'pln_abc123' }],
customFields: { firstName: 'Jane', country: 'Australia' }
})
});Error Handling
错误处理
The API returns errors as JSON with and fields. Common status codes:
codemessage- 400: Bad request (missing required fields, invalid formats, empty data)
- 404: Resource not found (wrong table key, nonexistent member/record)
Always check for these and surface clear messages to the user.
API返回的错误为JSON格式,包含和字段。常见状态码:
codemessage- 400: 请求错误(缺少必填字段、格式无效、数据为空)
- 404: 资源未找到(数据表key错误、成员/记录不存在)
请始终检查这些状态码,并向用户展示清晰的提示信息。
Tips
提示
- When deleting members, consider setting and
deleteStripeCustomerto avoid orphaned billing records.cancelStripeSubscriptions - Use with
findUniquewhen you know the exact record ID — it's simpler and returns a single record.where.id - The option in
_countis useful for getting totals without fetching all records.findMany - and
selectare mutually exclusive in queries — useincludeto expand relationships,includeto limit returned fields.select
- 删除成员时,考虑设置和
deleteStripeCustomer参数,以避免产生孤立的账单记录。cancelStripeSubscriptions - 当你知道确切的记录ID时,使用并搭配
findUnique参数——这种方式更简单,且返回单个记录。where.id - 中的
findMany选项可用于获取总数而无需获取所有记录,非常实用。_count - 在查询中和
select是互斥的——使用include展开关联关系,使用include限制返回的字段。select