创建会话与发送消息
GET /v1/ask/identity
GET /v1/ask/identity
Authorization: Bearer YOUR_HIOBUY_PRODUCTION_KEY{
"data": {
"app": {
"id": "app_example",
"name": "Example integration"
},
"api_key": {
"environment": "production",
"scopes": [
"supplier_inquiry:read",
"supplier_inquiry:write"
]
},
"inquiry": {
"enabled": true,
"mapped": true,
"read": true,
"write": true,
"webhook_configured": true
}
}
}后端请求 https://api.hiobuy.com,使用 Authorization: Bearer YOUR_HIOBUY_PRODUCTION_KEY。HIOBuy 管理员为 App 开通供应商咨询并配置 V2 绑定;真实聊天需要 production Key 及 supplier_inquiry:read / supplier_inquiry:write。身份检查接受任意有效 Key;测试 Key 返回 environment=sandbox,不能发起真实聊天。咨询能力不要求开通仓储履约。
创建会话
external_user_id 稳定标识客户;external_conversation_id 稳定标识客户 + 商品 + 本轮会话。两者均为 1–128 字符,匹配 [A-Za-z0-9][A-Za-z0-9._:@-]{0,127}。每个 POST 必须带 Idempotency-Key,长度 1–128 个可打印 ASCII 字符。发送前保存请求体和 Key;超时后使用完全相同的请求重试。相同标识或 Key 搭配不同内容返回 409。已结束会话不会重开,再次咨询应使用新的轮次 ID。
language 是可选的客户语言提示,使用规范 BCP 47 标签,如 en、en-US;未知时省略或传 null。target_language 是面向客户的回复语言。自动语言检测和翻译任务细节属于客服私有元数据。已知语言时直接传入;接入方无需额外调用翻译预览。
POST /v1/ask/conversations
Authorization: Bearer YOUR_HIOBUY_PRODUCTION_KEY
Content-Type: application/json
Idempotency-Key: create-customer-42-product-1
{
"external_conversation_id": "customer-42-1688-673124809943-1",
"external_user_id": "customer-42",
"language": "en",
"context": {
"type": "product",
"product_url": "https://detail.1688.com/offer/673124809943.html",
"product_id": "673124809943",
"product_title": "Knitted shoulder bag"
}
}{
"data": {
"id": "11111111-1111-4111-8111-111111111111",
"external_app_id": "hiobuy:app_example",
"external_conversation_id": "customer-42-1688-673124809943-1",
"external_user_id": "customer-42",
"language": "en",
"context": {
"type": "product",
"product_url": "https://detail.1688.com/offer/673124809943.html",
"product_id": "673124809943",
"product_title": "Knitted shoulder bag"
},
"target_language": "en",
"status": "pending",
"last_message_at": null,
"created_at": "2026-11-13T13:00:00.000Z",
"updated_at": "2026-11-13T13:00:00.000Z"
}
}发送消息
创建成功后,将 data.id 保存为会话 UUID,再发送首条客户消息。client_message_id 也是稳定的 1–128 字符标识。当前使用 type=text;content 上限为 10,000 个 Unicode 码点,除非附带商品卡片,否则不能为空。仅首条客户消息可带 product_card:URL 必须是规范 HTTPS 1688 / 淘宝 / 天猫商品链接,标题为 1–200 个纯文本字符,可选 price_label 最多 64 字符。后续消息继续使用相同会话,不再发送卡片。示例 UUID 须替换为创建接口实际返回的值。
POST /v1/ask/conversations/11111111-1111-4111-8111-111111111111/messages
Authorization: Bearer YOUR_HIOBUY_PRODUCTION_KEY
Content-Type: application/json
Idempotency-Key: send-customer-message-001
{
"client_message_id": "customer-message-001",
"type": "text",
"content": "Can the supplier provide neutral packaging?",
"product_card": {
"url": "https://detail.1688.com/offer/673124809943.html",
"title": "Knitted shoulder bag",
"price_label": "CNY 6.50"
}
}201 Created / 200 OK
公开历史包含客户原文和已公开的客服回复,sender_type 为 customer 或 staff,不包含客服私有草稿、原稿及内部记录。明确开通发送后撤回的接入方,在翻译完成后立即公开客服回复,不再固定等待 30 秒。撤回期限从服务端公开事务起计 30 秒;公开 API 不返回此期限,不能根据 created_at 或 Webhook 到达时间推算。未确认兼容的旧接入方保留原有公开前等待行为。撤回后保留带 recalled_at 的最终占位,content 为空、无媒体,保留原消息 ID 与排序;不要自行添加 status=recalled。客户消息的 translation_status=pending 不表示投递失败,不要覆盖客户原文。
体验真实 Inquiry Demo ,或阅读 MIT 开源代码 。线上 Demo 在服务端固定 Key 和一个商品。自行接入时请配置自己的 production Key、商品、渠道与 HTTPS Webhook。演示或测试会话必须设置 context.source=inquiry_demo;普通业务会话省略该字段。
图片上传
先向 HIOBuy 确认图片权限。由后端发送 PNG/JPEG/WebP 原始二进制,携带稳定的 Idempotency-Key、匹配的 Content-Type 及 X-Image-Filename(非 ASCII 文件名使用百分号编码,解码后最多 128 个字符)。不使用 multipart、base64 JSON 或远程 URL。上传前等比例缩小至宽、高均不超过 2400 像素,每张不超过 10 MiB。响应只返回元数据,不返回公开链接。
随后在同一会话发送 attachment_ids,最多四个当前操作接入方有权访问且未绑定、未过期的上传 ID。纯图片使用 type=image、content="";文字配图使用 type=text 和正文。首条消息的 product_card.image_attachment_id 如有提供,也必须包含在 attachment_ids 中。后端仍需校验客户对会话的权限。上传与发送是两个操作,分别保存各自的 ID 与幂等键以便重试。
curl --request POST \
'https://api.hiobuy.com/v1/ask/conversations/11111111-1111-4111-8111-111111111111/attachments' \
--header 'Authorization: Bearer YOUR_HIOBUY_PRODUCTION_KEY' \
--header 'Idempotency-Key: upload-packaging-001' \
--header 'Content-Type: image/png' \
--header 'X-Image-Filename: packaging.png' \
--data-binary '@packaging.png'{
"data": {
"id": "33333333-3333-4333-8333-333333333333",
"filename": "packaging.png",
"content_type": "image/png",
"size": 12345,
"width": 1200,
"height": 800,
"content_path": "/v1/ask/attachments/33333333-3333-4333-8333-333333333333/content"
}
}POST /v1/ask/conversations/11111111-1111-4111-8111-111111111111/messages
Authorization: Bearer YOUR_HIOBUY_PRODUCTION_KEY
Content-Type: application/json
Idempotency-Key: send-packaging-001
{
"client_message_id": "customer-image-001",
"type": "image",
"content": "",
"attachment_ids": [
"33333333-3333-4333-8333-333333333333"
]
}将 content_path 相对 https://api.hiobuy.com 解析,用服务端 HIOBuy Bearer Key 和读取权限获取内容,只向有权访问该会话的客户转发。不要暴露 Key,也不要将路径当作公开 R2 地址;?download=1 可请求下载。撤回后移除媒体展示及公开缓存。当前上传契约不保证病毒扫描、元数据清除或自动重新编码,接入文档不应作此承诺。类型、大小、尺寸不合规则明确报错(包括 HTTP 413/415/422);上游未开通媒体权限可能映射为 502 HIOASK_INTEGRATION_REJECTED。
获取支持
需要集成帮助?请联系开发者支持 support@hiobuy.com · 预计 1–2 个工作日内回复