memberstack-admin-api

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Memberstack 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_KEY
Base URL:
https://admin.memberstack.com
Data Tables endpoints use the
/v2/
prefix; Member endpoints do not.
所有请求都需要通过请求头传递API key:
x-api-key: YOUR_API_KEY
Base 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
    .env
    file (e.g.,
    MEMBERSTACK_API_KEY=sk_...
    ) and read it via
    process.env.MEMBERSTACK_API_KEY
    (Node) or
    os.environ["MEMBERSTACK_API_KEY"]
    (Python).
  • 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
    .env
    file or secret store instead.
切勿在对话中直接向用户索要其API key。API key是敏感凭证,绝不能出现在聊天内容、展示给用户的代码片段中,也不能硬编码到源文件中。应采取以下方式:
  • 将密钥存储在
    .env
    文件中(例如
    MEMBERSTACK_API_KEY=sk_...
    ),并通过
    process.env.MEMBERSTACK_API_KEY
    (Node.js)或
    os.environ["MEMBERSTACK_API_KEY"]
    (Python)读取。
  • 或者使用平台的密钥/环境变量管理功能(例如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.
ActionMethodEndpoint
List membersGET
/members
Get memberGET
/members/:id_or_email
Create memberPOST
/members
Update memberPATCH
/members/:id
Delete memberDELETE
/members/:id
Add free planPOST
/members/:id/add-plan
Remove free planPOST
/members/:id/remove-plan
Key concepts:
  • Member IDs start with
    mem_
    , plan IDs with
    pln_
    , connection IDs with
    con_
  • Members can be looked up by ID or URL-encoded email
  • Pagination uses cursor-based
    after
    +
    limit
    (max 200)
  • Members have
    customFields
    ,
    metaData
    ,
    json
    ,
    permissions
    , and
    planConnections
用于管理成员、其个人资料、套餐关联和元数据的端点。
操作请求方法端点
列出成员GET
/members
获取成员GET
/members/:id_or_email
创建成员POST
/members
更新成员PATCH
/members/:id
删除成员DELETE
/members/:id
添加免费套餐POST
/members/:id/add-plan
移除免费套餐POST
/members/:id/remove-plan
核心概念:
  • 成员ID以
    mem_
    开头,套餐ID以
    pln_
    开头,关联ID以
    con_
    开头
  • 可通过ID或URL编码的邮箱查找成员
  • 分页使用基于游标(cursor)的
    after
    +
    limit
    参数(最大值200)
  • 成员包含
    customFields
    (自定义字段)、
    metaData
    (元数据)、
    json
    permissions
    (权限)和
    planConnections
    (套餐关联)

Data Tables API

数据表API

Endpoints for managing structured data with typed fields, relationships, and querying.
ActionMethodEndpoint
List tablesGET
/v2/data-tables
Get tableGET
/v2/data-tables/:tableKey
Create recordPOST
/v2/data-tables/:tableKey/records
Update recordPUT
/v2/data-tables/:tableKey/records/:recordId
Delete recordDELETE
/v2/data-tables/:tableKey/records/:recordId
Query recordsPOST
/v2/data-tables/:tableKey/records/query
Key concepts:
  • Tables are referenced by key (e.g.,
    products
    ) or ID (e.g.,
    tbl_...
    )
  • Records hold data as key-value pairs matching field definitions
  • Querying supports
    findMany
    and
    findUnique
    with rich filtering (
    equals
    ,
    contains
    ,
    gt
    ,
    lt
    ,
    in
    , logical operators
    AND
    /
    OR
    /
    NOT
    )
  • Pagination via
    take
    (max 100),
    skip
    , or cursor-based
    after
  • Field types include TEXT, NUMBER, DECIMAL, BOOLEAN, DATE, EMAIL, URL, REFERENCE, and MEMBER_REFERENCE variants
用于管理带类型字段、关联关系和查询功能的结构化数据的端点。
操作请求方法端点
列出数据表GET
/v2/data-tables
获取数据表GET
/v2/data-tables/:tableKey
创建记录POST
/v2/data-tables/:tableKey/records
更新记录PUT
/v2/data-tables/:tableKey/records/:recordId
删除记录DELETE
/v2/data-tables/:tableKey/records/:recordId
查询记录POST
/v2/data-tables/:tableKey/records/query
核心概念:
  • 数据表可通过key(例如
    products
    )或ID(例如
    tbl_...
    )引用
  • 记录以与字段定义匹配的键值对形式存储数据
  • 查询支持
    findMany
    findUnique
    ,并提供丰富的过滤条件(
    equals
    contains
    gt
    lt
    in
    ,以及逻辑运算符
    AND
    /
    OR
    /
    NOT
  • 分页可通过
    take
    (最大值100)、
    skip
    或基于游标(cursor)的
    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
code
and
message
fields. Common status codes:
  • 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格式,包含
code
message
字段。常见状态码:
  • 400: 请求错误(缺少必填字段、格式无效、数据为空)
  • 404: 资源未找到(数据表key错误、成员/记录不存在)
请始终检查这些状态码,并向用户展示清晰的提示信息。

Tips

提示

  • When deleting members, consider setting
    deleteStripeCustomer
    and
    cancelStripeSubscriptions
    to avoid orphaned billing records.
  • Use
    findUnique
    with
    where.id
    when you know the exact record ID — it's simpler and returns a single record.
  • The
    _count
    option in
    findMany
    is useful for getting totals without fetching all records.
  • select
    and
    include
    are mutually exclusive in queries — use
    include
    to expand relationships,
    select
    to limit returned fields.
  • 删除成员时,考虑设置
    deleteStripeCustomer
    cancelStripeSubscriptions
    参数,以避免产生孤立的账单记录。
  • 当你知道确切的记录ID时,使用
    findUnique
    并搭配
    where.id
    参数——这种方式更简单,且返回单个记录。
  • findMany
    中的
    _count
    选项可用于获取总数而无需获取所有记录,非常实用。
  • 在查询中
    select
    include
    是互斥的——使用
    include
    展开关联关系,使用
    select
    限制返回的字段。