运行时依赖
安装命令
点击复制技能文档
Mayar CLI — Agent Skill 本文档描述了如何安装、认证和使用Mayar CLI工具的AI代理(Claude Code、OpenClaw等)。 快速开始 # 总是使用最新版本 — 无需安装步骤 npx -y mayar@latest whoami 认证流程 步骤1 — 检测活跃用户 运行whoami检查是否已经配置了有效的API密钥: npx -y mayar@latest whoami --json 成功输出包含“valid”: true和商家的名称、电子邮件和accountId。如果密钥有效,则直接进行请求的任务。 步骤2 — 处理缺失或无效密钥 如果whoami退出非零或返回“valid”: false,代理必须停止并要求用户提供其API密钥,使用以下选项之一: 选项A — 环境变量(推荐用于非交互式代理): 要求用户设置:export MAYAR_API_KEY= 然后重新运行原始命令。 选项B — 单次标志(单个命令): 要求用户提供密钥并传递:npx -y mayar@latest --api-key whoami 选项C — 交互式设置(仅限终端代理): 如果代理具有交互式TTY访问权限:npx -y mayar@latest init 代理绝不能伪造或猜测API密钥。总是停止并要求用户。 在https://web.mayar.id → Integration → API Key处获取密钥。 使用参考 所有命令使用以下模式:npx -y mayar@latest [subcommand] [args] [flags] 账户 npx -y mayar@latest whoami # 验证密钥 + 显示商家身份 npx -y mayar@latest balance # 账户余额 发票 npx -y mayar@latest invoice list [--page N --pageSize N] npx -y mayar@latest invoice get npx -y mayar@latest invoice close npx -y mayar@latest invoice reopen npx -y mayar@latest invoice create --data '' npx -y mayar@latest invoice create --data @file.json 产品 npx -y mayar@latest product list [--page N --pageSize N] npx -y mayar@latest product search npx -y mayar@latest product type npx -y mayar@latest product get npx -y mayar@latest product close npx -y mayar@latest product reopen 付款 npx -y mayar@latest payment list npx -y mayar@latest payment get npx -y mayar@latest payment close npx -y mayar@latest payment reopen npx -y mayar@latest payment create --data '' 客户 npx -y mayar@latest customer list [--page N --pageSize N] npx -y mayar@latest customer create --data '' 交易 npx -y mayar@latest tx list [--page N --pageSize N] # 已付 npx -y mayar@latest tx unpaid [--page N --pageSize N] # 未付 动态二维码 npx -y mayar@latest qrcode Webhooks npx -y mayar@latest webhook register npx -y mayar@latest webhook test npx -y mayar@latest webhook history [--page N --pageSize N] 全局标志 标志 描述 --json 输出原始JSON(机器可读,管道到jq) --api-key 覆盖保存的密钥用于此调用 --page N 分页页码(默认1) --pageSize N 每页项数(默认10) -v, --version 打印版本 -h, --help 打印帮助 JSON输出 代理需要解析响应时始终使用--json: npx -y mayar@latest invoice list --json | jq '.data[] | {id, status}' npx -y mayar@latest whoami --json | jq '{valid, name: .decoded.name}' 错误处理 非零退出代码 = 命令失败 whoami --json中的“valid”: false = 无效或过期的API密钥 HTTP错误在stderr上打印API — 代理决策树 START └─ 运行:npx -y mayar@latest whoami --json ├─ 退出0 + valid=true → 继续任务 └─ 退出非零或valid=false └─ 询问用户:“请提供您的Mayar API密钥。您可以:(A)设置MAYAR_API_KEY环境变量,或(B)运行:npx -y mayar@latest init 从https://web.mayar.id → Integration → API Key获取密钥。