docs: 补充档案回流接口调用说明(docs/api.md + 前台 API 文档页)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
+58
@@ -112,6 +112,64 @@ curl "https://goods.tangshasha.com/api/v1/products/barcode/5449000000996"
|
||||
|
||||
### `GET /sources/{id}` — 数据来源
|
||||
|
||||
## 档案回流(写接口,需 API Key)
|
||||
|
||||
> 仅供进销存等机器调用方使用:把档案里**尚未收录**的商品批量回流到站点,进入人工审核队列,审核通过后才会收录。**必须携带 API Key**(与上文同一类 `og_live_` 密钥),不会直接写入商品。
|
||||
|
||||
### `POST /api/public/backflow` — 批量回流未收录商品
|
||||
|
||||
- 鉴权:请求头携带 `X-API-Key: og_live_xxxxxxxx`(或 `Authorization: Bearer og_live_xxxxxxxx`)。缺失/无效/已吊销返回 `401`。
|
||||
- 请求体:商品对象**数组**(与公众投稿同结构),单次最多 `1000` 条。常用字段:
|
||||
|
||||
| 字段 | 必填 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| `name` | 是 | 商品名称 |
|
||||
| `gtin` | 否 | 条码(GTIN)。强烈建议提供,用于去重 |
|
||||
| `brand_name` | 否 | 品牌名 |
|
||||
| `category_id` | 否 | 品类编码,如 `food.beverages` |
|
||||
| `net_content_value` / `net_content_unit` | 否 | 净含量数值 / 单位 |
|
||||
| `country_of_origin` | 否 | 产地 |
|
||||
| `ingredients_text` | 否 | 配料表 |
|
||||
| `nutriments` | 否 | 营养成分对象 |
|
||||
| `msrp` | 否 | 零售价快照数组,元素含 `amount`/`currency`/`region`/`effective_date` |
|
||||
| `note` | 否 | 备注 |
|
||||
|
||||
> 来源会自动标记为 `source="backflow"`,在后台审核队列中与公众投稿区分,无需调用方提供。
|
||||
|
||||
- 去重(按 `gtin` 逐条判断,互不影响):
|
||||
- 该条码已收录为商品 → `exists`,跳过;
|
||||
- 已存在同条码的待审核回流 → `duplicate`,跳过(避免反复刷队列);
|
||||
- 否则入队 → `queued`(status=`pending`,等待后台审核);
|
||||
- 名称为空等 → `invalid`。
|
||||
|
||||
```bash
|
||||
curl -X POST "https://goods.tangshasha.com/api/public/backflow" \
|
||||
-H "X-API-Key: og_live_xxxxxxxx" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '[
|
||||
{"name":"某某牛奶 250ml","gtin":"6901234567890","brand_name":"某品牌",
|
||||
"net_content_value":250,"net_content_unit":"ml",
|
||||
"msrp":[{"amount":3.5,"currency":"CNY","region":"CN"}]},
|
||||
{"name":"已收录商品","gtin":"5449000000996"}
|
||||
]'
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"total": 2,
|
||||
"queued": 1,
|
||||
"exists": 1,
|
||||
"duplicate": 0,
|
||||
"invalid": 0,
|
||||
"results": [
|
||||
{ "gtin": "6901234567890", "name": "某某牛奶 250ml", "status": "queued", "id": "<submission-id>" },
|
||||
{ "gtin": "5449000000996", "name": "已收录商品", "status": "exists", "reason": "该条码商品已收录" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
审核通过后,系统按提交内容**新建商品**;若审核时该条码已存在商品,则**补全**到已有商品(逻辑与公众投稿一致)。
|
||||
|
||||
## 免责声明
|
||||
|
||||
数据可能存在误差或滞后,按「现状」提供,不构成医疗/购买建议。商品资料版权归各原始来源所有,请遵循其许可(如 OpenFoodFacts 的 ODbL),引用时请注明天工商品档案公共仓及原始来源。
|
||||
|
||||
@@ -343,6 +343,41 @@ curl -H "Authorization: Bearer og_live_xxxxxxxx" ${BASE}/products/search?q=牛
|
||||
}`}
|
||||
/>
|
||||
|
||||
<Endpoint
|
||||
method="POST"
|
||||
path="/api/public/backflow"
|
||||
title="档案回流(批量回流未收录商品,需 API Key)"
|
||||
desc="供进销存等机器调用方使用:把档案里尚未收录的商品批量推送过来,进入人工审核队列,审核通过后才收录。必须携带 API Key(与上文同一类 og_live_ 密钥),不会直接写入商品。请求体为商品对象数组(与公众投稿同结构),单次最多 1000 条;按条码 GTIN 逐条去重,返回每条结果:queued(入队待审)/ exists(已收录跳过)/ duplicate(已有同条码待审跳过)/ invalid(无效,如名称为空)。"
|
||||
params={[
|
||||
{ name: "name", required: true, desc: "商品名称(数组中每个元素)" },
|
||||
{ name: "gtin", desc: "条码(GTIN),强烈建议提供,用于去重" },
|
||||
{ name: "brand_name", desc: "品牌名" },
|
||||
{ name: "category_id", desc: "品类编码,如 food.beverages" },
|
||||
{ name: "net_content_value / net_content_unit", desc: "净含量数值 / 单位" },
|
||||
{ name: "country_of_origin", desc: "产地" },
|
||||
{ name: "msrp", desc: "零售价快照数组,元素含 amount/currency/region/effective_date" },
|
||||
{ name: "note", desc: "备注" },
|
||||
]}
|
||||
example={`curl -X POST ${ORIGIN}/api/public/backflow \\
|
||||
-H "X-API-Key: og_live_xxxxxxxx" \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-d '[
|
||||
{"name":"某某牛奶 250ml","gtin":"6901234567890","brand_name":"某品牌",
|
||||
"net_content_value":250,"net_content_unit":"ml",
|
||||
"msrp":[{"amount":3.5,"currency":"CNY","region":"CN"}]},
|
||||
{"name":"已收录商品","gtin":"5449000000996"}
|
||||
]'`}
|
||||
response={`{
|
||||
"total": 2, "queued": 1, "exists": 1, "duplicate": 0, "invalid": 0,
|
||||
"results": [
|
||||
{ "gtin": "6901234567890", "name": "某某牛奶 250ml",
|
||||
"status": "queued", "id": "<submission-id>" },
|
||||
{ "gtin": "5449000000996", "name": "已收录商品",
|
||||
"status": "exists", "reason": "该条码商品已收录" }
|
||||
]
|
||||
}`}
|
||||
/>
|
||||
|
||||
<Endpoint
|
||||
method="POST"
|
||||
path="/api/v1/register"
|
||||
|
||||
Reference in New Issue
Block a user