Install
openclaw skills install @crab-xieyujin/xianyu-api-client-skillSecure Xianyu Guanjia API client with endpoint allowlisting, enforced confirmation for high-risk actions, dry-run mode, and unsafe methods for automation.
openclaw skills install @crab-xieyujin/xianyu-api-client-skill这是一个专为闲鱼管家开放平台设计的基础API客户端技能,为所有闲鱼相关操作提供安全、可靠的底层通信能力。本技能处理了所有复杂的认证、签名、错误处理等技术细节,让您能够专注于业务逻辑开发,而无需关心底层API实现。
在使用本技能之前,您必须完成以下配置:
203413189371893o9wl81dncmvby3ijpq7eur456zhgtaxs将获取到的密钥信息配置为环境变量,这是最安全的方式:
# Linux/Mac系统
export XIAN_YU_APP_KEY=您的应用KEY
export XIAN_YU_APP_SECRET=您的应用密钥
# Windows系统(命令提示符)
set XIAN_YU_APP_KEY=您的应用KEY
set XIAN_YU_APP_SECRET=您的应用密钥
如果您不想使用环境变量,也可以在代码中直接传入密钥:
from xianyu_api_client_skill import XianYuAPIClient
client = XianYuAPIClient(
app_key="您的应用KEY",
app_secret="您的应用密钥"
)
创建商品完整参数说明(基于实际成功经验):
{
"item_biz_type": 2,
"sp_biz_type": 1,
"channel_cat_id": "e11455b218c06e7ae10cfa39bf43dc0f",
"price": 29900,
"original_price": 39900,
"express_fee": 0,
"stock": 1,
"outer_id": "YOUR_UNIQUE_ID",
"stuff_status": 100,
"publish_shop": [{
"user_name": "您的闲鱼号", // 必需!如:xy137114666612
"images": ["https://example.com/image.jpg"], // 必需!至少1张图片URL
"title": "商品标题", // ≤60字符,不能包含表情符号
"content": "详细商品描述",
"service_support": "SDR", // 固定值
"province": 110000, // 省代码
"city": 110100, // 市代码
"district": 110101 // 区代码
}]
}
关键注意事项:
✅ user_name必需:必须填写您的真实闲鱼号
✅ images必需:必须提供有效的图片URL数组
✅ 标题限制:不超过60字符,不能包含表情符号(🎯❌)
✅ 价格单位:以分为单位(29900 = ¥299)
✅ 成功响应:code=0 表示成功,不是200
查询商品详情和列表
编辑商品信息
商品上下架操作
库存管理
商品删除
本技能采用强制确认机制,确保所有高风险操作都是安全且可控的:
所有写操作默认需要用户确认,无法跳过。以下操作会暂停并等待用户确认:
/api/open/product/create)/api/open/product/edit)/api/open/product/del)/api/open/product/onshelf, /api/open/product/offshelf)/api/open/order/modifyprice)/api/open/order/logistics)# 默认安全模式:高风险操作会暂停等待确认
client.request("/api/open/product/create", product_data)
client.create_product(product_data)
client.delete_product(product_data)
client.modify_order_price(order_data)
在实际执行前,先用 dry_run=True 预览请求数据:
# 预览请求,不实际发送
result = client.request("/api/open/product/create", product_data, dry_run=True)
对于确认需要自动化脚本使用的场景,提供了 _unsafe 后缀的方法。这些方法跳过所有确认,请务必先用 dry_run=True 预览:
# 1. 先预览确认数据正确
client.request_unsafe("/api/open/product/create", product_data, dry_run=True)
# 2. 预览无误后执行(跳过确认)
result = client.request_unsafe("/api/open/product/create", product_data)
# 或者使用便捷方法
client.create_product_unsafe(product_data)
client.delete_product_unsafe(product_data)
client.modify_order_price_unsafe(order_data)
警告:_unsafe 方法跳过所有安全确认,仅适用于:
This skill interacts with the Xianyu Guanjia Open Platform using API credentials. The following security controls are enforced at the code level.
This skill should only be installed if you need Xianyu shop automation. It is designed exclusively for managing products, orders, and store information on the Xianyu marketplace. It does not access any other platform, service, or local resource beyond the Xianyu Open Platform API.
All API calls are restricted to a hardcoded allowlist in __init__.py. Any request to an endpoint outside this list is rejected with a ValueError before any network call is made. The allowed endpoints are:
| Endpoint | Type | Confirmation |
|---|---|---|
/api/open/product/detail | Read | No |
/api/open/product/list | Read | No |
/api/open/order/detail | Read | No |
/api/open/order/list | Read | No |
/api/open/user/shopinfo | Read | No |
/api/open/category/query | Read | No |
/api/open/express/companies | Read | No |
/api/open/area/geo | Read | No |
/api/open/product/create | Write | Yes |
/api/open/product/edit | Write | Yes |
/api/open/product/del | Write | Yes |
/api/open/product/onshelf | Write | Yes |
/api/open/product/offshelf | Write | Yes |
/api/open/order/modifyprice | Write | Yes |
/api/open/order/logistics | Write | Yes |
All write operations (create, edit, delete, on/off-shelf, price change, logistics) are defined in HIGH_RISK_ENDPOINTS and require interactive user confirmation by default. The default request() method calls _do_request(endpoint, data, confirm=True), which prints the full request payload and waits for explicit y input before proceeding.
# Default path: ALWAYS prompts for confirmation before write operations
client.request("/api/open/product/create", product_data) # prompts [y/N]
client.create_product(product_data) # prompts [y/N]
client.delete_product(product_data) # prompts [y/N]
client.modify_order_price(order_data) # prompts [y/N]
There is no way to suppress confirmation through the default request() method.
All methods support dry_run=True, which prints the full request payload without making any network call. Always use dry-run before executing write operations:
result = client.request("/api/open/product/create", product_data, dry_run=True)
# Output: [Dry Run] full JSON payload — no API call made
For controlled automation scenarios, the skill provides separately named _unsafe methods (request_unsafe, create_product_unsafe, delete_product_unsafe, modify_order_price_unsafe) that skip the interactive confirmation prompt.
These methods are intentionally separated from the default safe path to prevent accidental use. They should only be used when:
dry_run=True_unsafe variant by nameThe _unsafe methods are not accessible through the default request() path. An agent or script must explicitly call request_unsafe() or create_product_unsafe() by name.
This skill reads Xianyu API credentials (XIAN_YU_APP_KEY, XIAN_YU_APP_SECRET) from environment variables or constructor parameters. These credentials are used solely for signing API requests to the Xianyu Open Platform.
Required practices:
本技能是其他闲鱼相关技能的基础依赖:
如果遇到问题,请按以下步骤排查:
配置完成后,您就可以在其他闲鱼技能中无缝使用本技能,或者直接调用其提供的API方法进行自定义开发。