在电商上架、商品主数据补全、扫码入库、商品信息核验等场景里,开发者经常会遇到一个很实际的问题:手里只有一串商品条码,怎么快速拿到商品名称、品牌、规格、厂商、分类和商品图?

如果这些信息都靠人工录入,效率会比较低;如果直接在业务系统里接入商品条码查询 API,就可以把“扫码”变成结构化数据查询。本文以 ApiZero 的「商品条码查询(GS1 中国)」接口为例,演示如何通过一个 GET 请求,根据商品条形码获取 GS1 中国相关的商品注册信息。

接口能做什么

这个接口面向国内 GS1 商品条码查询场景,核心能力是:输入商品条码,返回对应的商品基础信息和注册信息。

它适合用在这些业务里:

  • 电商商品上架时,根据条码补全商品名称、品牌、规格等字段
  • 仓储、门店、扫码入库系统中,快速识别商品基础信息
  • 商品资料库建设时,用条码统一关联 GTIN、品类和厂商信息
  • 商品审核、资料核验、数据清洗等需要结构化商品信息的流程

接口返回的数据字段比较完整,常用字段包括:

  • barcode:13 位标准 EAN-13 条码
  • gtin14:14 位 GTIN 标准化结果
  • found:是否查询到对应商品信息
  • registered:条码是否已注册
  • name:完整商品名
  • brand:品牌名称
  • category:商品分类
  • specification:规格
  • net_content:净含量
  • manufacturer:发布企业名称
  • images:官方商品图 URL 数组

请求方式

接口地址:

GET https://v1.apizero.cn/api/barcode-gs1

必填参数:

参数名 类型 是否必填 说明 示例
code string 商品条形码,支持 8 / 12 / 13 / 14 位纯数字,也支持 16 位 AI(01) 前缀 + GTIN-14 6921168509256

鉴权方式:

  • 可以先直接使用 code 参数进行快速调试
  • 正式项目中可以按控制台获取的 API Key 方式接入
  • 文档示例中也支持在请求 URL 中追加 key=YOUR_API_KEY

完整请求示例:

curl "https://v1.apizero.cn/api/barcode-gs1?code=6921168509256"

带 Key 的写法可以这样组织:

curl "https://v1.apizero.cn/api/barcode-gs1?code=6921168509256&key=YOUR_API_KEY"

返回示例

下面是一次商品条码查询的返回结构示例:

{
  "code": 0,
  "msg": "成功",
  "data": {
    "barcode": "6921168509256",
    "gtin14": "06921168509256",
    "found": true,
    "registered": true,
    "registration_message": "该商品条码已经在中国物品编码中心注册,编码信息已按规定通报。",
    "name": "农夫山泉饮用天然水",
    "brand": "农夫山泉",
    "general_name": "水(瓶装、桶装等)",
    "category": "水(瓶装、桶装等)(10000232)",
    "specification": "550毫升",
    "net_content": "550毫升",
    "sale_date": "2008-07-24",
    "manufacturer": "农夫山泉股份有限公司",
    "images": [
      "https://www.gds.org.cn/userfile1/uploadb/gra/sj211126172650708225/06921168509256/06921168509256.1.jpg"
    ],
    "qr_active_date": "2008年07月24日",
    "product_create_date": "2008年11月07日",
    "use_days": 6393
  },
  "request_id": "mpdtl2tx8f03243c"
}

业务上通常先看三层信息:

  • code 是否为 0,用于判断接口请求是否成功
  • data.found 是否为 true,用于判断条码是否匹配到商品资料
  • data 中的商品字段,用于写入商品库、审核页或业务展示页

Python 调用示例

下面用 Python 的 requests 发起请求,并把商品核心字段解析出来:

import requests

endpoint = "https://v1.apizero.cn/api/barcode-gs1"

params = {
    "code": "6921168509256",
    # "key": "YOUR_API_KEY",
}

resp = requests.get(endpoint, params=params, timeout=10)
result = resp.json()

if result.get("code") == 0 and result.get("data", {}).get("found"):
    item = result["data"]
    print("商品名称:", item.get("name"))
    print("品牌:", item.get("brand"))
    print("规格:", item.get("specification"))
    print("净含量:", item.get("net_content"))
    print("分类:", item.get("category"))
    print("厂商:", item.get("manufacturer"))
    print("GTIN-14:", item.get("gtin14"))
else:
    print("未查询到商品信息:", result.get("msg"))

如果要把结果存进业务系统,可以先抽取一个更轻量的结构:

def normalize_barcode_item(payload: dict) -> dict | None:
    data = payload.get("data") or {}
    if payload.get("code") != 0 or not data.get("found"):
        return None

    return {
        "barcode": data.get("barcode"),
        "gtin14": data.get("gtin14"),
        "name": data.get("name"),
        "brand": data.get("brand"),
        "category": data.get("category"),
        "specification": data.get("specification"),
        "net_content": data.get("net_content"),
        "manufacturer": data.get("manufacturer"),
        "image": (data.get("images") or [None])[0],
    }

这样后续无论是写入 MySQL、同步到商品中心,还是返回给前端展示,都可以保持字段清晰。

JavaScript 调用示例

在 Node.js 或现代前端环境中,可以直接使用 fetch

const endpoint = "https://v1.apizero.cn/api/barcode-gs1";

const params = new URLSearchParams({
  code: "6921168509256",
  // key: "YOUR_API_KEY",
});

const response = await fetch(`${endpoint}?${params.toString()}`);
const result = await response.json();

if (result.code === 0 && result.data?.found) {
  const item = result.data;

  console.log({
    name: item.name,
    brand: item.brand,
    gtin14: item.gtin14,
    category: item.category,
    specification: item.specification,
    manufacturer: item.manufacturer,
    image: item.images?.[0],
  });
} else {
  console.log("未查询到商品信息", result.msg);
}

如果是在后端服务中封装,可以把它做成一个独立函数:

export async function queryBarcodeGs1(code, apiKey) {
  const params = new URLSearchParams({ code });
  if (apiKey) params.set("key", apiKey);

  const res = await fetch(
    `https://v1.apizero.cn/api/barcode-gs1?${params.toString()}`
  );

  const json = await res.json();
  const data = json.data || {};

  if (json.code !== 0 || !data.found) {
    return null;
  }

  return {
    barcode: data.barcode,
    gtin14: data.gtin14,
    name: data.name,
    brand: data.brand,
    category: data.category,
    specification: data.specification,
    netContent: data.net_content,
    manufacturer: data.manufacturer,
    image: data.images?.[0] || null,
  };
}

字段解析建议

商品条码接口的价值不只是“查到商品名”,更重要的是能把分散的商品资料转换成业务系统可使用的结构化字段。

实际接入时,可以把字段分成几类:

字段类别 对应字段 适合用途
条码标准化 barcodegtin14 商品唯一标识、数据去重
商品展示 namebrandspecificationnet_contentimages 上架页、详情页、审核页
分类信息 general_namecategorycategory_code 类目匹配、商品库治理
企业信息 manufactureraddresscountry 资料核验、供应链管理
时间信息 sale_dateqr_active_dateproduct_create_datecompany_register_date 商品资料追踪、数据更新时间参考

其中 gtin14 很适合做商品数据统一编码。比如同一个商品在不同系统里可能出现 13 位条码、14 位 GTIN 或带 AI(01) 前缀的编码,后端可以在入库前统一转换和存储,减少后续匹配成本。

适用场景

1. 电商上架资料补全

商家录入商品条码后,系统自动查询商品名、品牌、规格、净含量和商品图。这样可以减少重复录入,提高商品上架流程的效率。

2. 仓储扫码入库

仓库系统扫描商品条码后,可以实时补齐商品基础资料,方便生成入库单、库存记录和商品档案。

3. 商品主数据治理

当企业内部存在多个商品系统时,可以通过条码和 GTIN-14 做统一映射,把品牌、品类、规格、厂商等字段整理成标准商品库。

4. 审核和核验工作台

在商品审核、供应链资料核验、采购系统等场景中,接口可以作为商品资料查询入口,把条码信息快速转换成可读、可展示、可落库的结构化数据。

小结

「商品条码查询(GS1 中国)」接口的接入方式比较直接:一个 GET 地址,一个必填 code 参数,就可以把商品条码转换成商品名称、品牌、规格、分类、厂商、GTIN-14 和商品图等结构化信息。

对于开发者来说,它的优势在于返回字段清晰,适合快速封装成后端查询函数,也适合接入到电商上架、扫码入库、商品主数据治理等业务流程中。只要把条码查询结果做好标准化处理,就可以在业务系统里形成稳定的商品信息底座。

参考接口文档:https://apizero.cn/marketplace/barcode-gs1在这里插入图片描述

Logo

电商企业物流数字化转型必备!快递鸟 API 接口,72 小时快速完成物流系统集成。全流程实战1V1指导,营造开放的API技术生态圈。

更多推荐