SuperAPI AI 工具集

cancel-and-restock

办公与效率

查看项目

更新于 10-15 11:08

技能介绍

用途 cancel-and-restock 用于取消未发货或部分发货的订单,并提供可配置的补货、退款和客户通知选项,无需进入 Shopify 管理后台操作。适用于欺诈异常处理、缺货取消,或客户在发货前请求取消。无法取消已完全发货的订单。

前提条件 已认证的 Shopify CLI 会话:shopify auth login --store <domain> API 权限范围:read_orders、write_orders

参数 store:string,必填,无默认值,店铺域名(如 mystore.myshopify.com) format:string,可选,默认 human,输出格式:human 或 json dry_run:bool,可选,默认 false,预览操作而不执行变更 order_id:string,必填,无默认值,订单的 GID(如 gid://shopify/Order/12345) reason:string,可选,默认 OTHER,取消原因:CUSTOMER、DECLINED、FRAUD、INVENTORY、STAFF、OTHER restock:bool,可选,默认 true,为已取消的订单行项目补货 refund:bool,可选,默认 true,对已捕获的付款发起退款 notify_customer:bool,可选,默认 true,向客户发送取消邮件 staff_note:string,可选,无默认值,记录在取消操作上的内部备注

安全性 ⚠️ 第 2 步执行 orderCancel,该操作不可逆。已取消的订单无法重新打开。若 refund 为 true,任何已捕获的付款会自动退款。若 restock 为 true,库存数量会立即恢复。提交前使用 dry_run: true 验证订单状态并确认其可取消。

工作流步骤 步骤 1:OPERATION: order — query 输入:id: <order_id> 预期输出:订单名称、displayFulfillmentStatus、displayFinancialStatus、cancelledAt(必须为 null)、fulfillmentOrders.status(必须为 OPEN 或 ON_HOLD——若任何履约订单为 IN_PROGRESS 或 CLOSED 则中止)

步骤 2:OPERATION: orderCancel — mutation 输入:orderId、reason、restock、refund、notifyCustomer、staffNote 预期输出:orderCancelUserErrors——成功时为空;订单现已取消并带有 cancelledAt 时间戳

GraphQL 操作

order:query — 已按 api_version 2025-01 校验

query OrderForCancel($id: ID!) { order(id: $id) { id name displayFulfillmentStatus displayFinancialStatus cancelledAt totalPriceSet { shopMoney { amount currencyCode } } lineItems(first: 50) { edges { node { id title quantity variant { id sku inventoryQuantity } } } } fulfillmentOrders(first: 5) { edges { node { id status } } } customer { id email firstName lastName } } }

orderCancel:mutation — 已按 api_version 2025-01 校验

mutation OrderCancel( $orderId: ID! $reason: OrderCancelReason! $restock: Boolean! $refund: Boolean! $notifyCustomer: Boolean! $staffNote: String ) { orderCancel( orderId: $orderId reason: $reason restock: $restock refund: $refund notifyCustomer: $notifyCustomer staffNote: $staffNote ) { orderCancelUserErrors { field message } userErrors { field message } } }

会话跟踪 Claude 必须在每个阶段输出以下内容。这是强制要求。

开始时输出: ╔══════════════════════════════════════════════╗ ║ SKILL: cancel-and-restock ║ ║ Store: <store domain> ║ ║ Started: <YYYY-MM-DD HH:MM UTC> ║ ╚══════════════════════════════════════════════╝

每个步骤后输出: [N/TOTAL] <QUERY|MUTATION> <OperationName> → Params: <brief summary of key inputs> → Result: <count or outcome>

若 dry_run: true,为每个变更步骤添加 [DRY RUN] 前缀且不执行该步骤。

完成时输出: format 为 human(默认)时: ══════════════════════════════════════════════ OUTCOME SUMMARY Order: <name> Cancellation reason: <reason> Restocked: <true|false> Refund issued: <true|false> Customer notified: <true|false> Errors: 0 Output: none ══════════════════════════════════════════════

format 为 json 时输出: { "skill": "cancel-and-restock", "store": "<domain>", "started_at": "<ISO8601>", "completed_at": "<ISO8601>", "dry_run": false, "steps": [ { "step": 1, "operation": "OrderForCancel", "type": "query", "params_summary": "order <id>", "result_summary": "<status>", "skipped": false }, { "step": 2, "operation": "OrderCancel", "type": "mutation", "params_summary": "reason: <reason>, restock: <bool>, refund: <bool>, notifyCustomer: <bool>", "result_summary": "cancelled at <timestamp>", "skipped": false } ], "outcome": { "order_name": "<name>", "reason": "<reason>", "restocked": true, "refund_issued": true, "customer_notified": true, "errors": 0, "output_file": null } }

输出格式 无 CSV 输出。会话摘要会内联报告取消结果。若 restock 为 true,列出恢复的变体 SKU 和数量。

错误处理 cancelledAt 不为 null:订单已取消,无需操作。 履约订单状态为 IN_PROGRESS:订单正在拣货/打包,联系仓库停止——一旦 IN_PROGRESS 便无法通过程序取消。 orderCancelUserErrors:订单已完全发货,改用 refund-and-reorder 技能。 未找到订单:无效的订单 GID,使用 order-lookup-and-summary 技能查找正确 ID。

最佳实践 始终先运行 dry_run: true——在提交取消前检查 displayFulfillmentStatus 和履约订单状态。 对高风险订单设置 reason: FRAUD——该原因会记录在 Shopify 的欺诈分析中。 若订单已被捕获(状态为 PAID),设置 refund: true——未退款的取消会导致客户争议。 对于大批量取消(例如缺货事件),使用 format: json 循环遍历订单 ID,为每次结果记录审计日志。 若仓库已开始拣货,不要通过 API 取消——直接联系他们,仅在他们确认未开始实际作业后再取消。