Daraz作为东南亚领先的电商平台,提供了丰富的API接口供开发者集成。获取商品详情数据是其核心功能之一,可用于价格监控、库存管理、数据分析等场景。本文将介绍如何调用Daraz的商品详情API接口。
1. API基础信息
- 接口类型:RESTful
- 请求方法:
GET - 认证方式:OAuth 2.0 (需提前申请
client_id和client_secret) - 数据格式:JSON
2. 接口地址
基础URL结构如下:
https://api.daraz.com/product/{item_id}/detail其中{item_id}需替换为目标商品的唯一标识符(如DS123456789)。
3. 请求参数
| 参数名 | 类型 | 必选 | 说明 |
|---|---|---|---|
item_id | string | 是 | 商品ID(路径参数) |
access_token | string | 是 | OAuth认证令牌 |
country | string | 是 | 国家代码(如PK、BD) |
4. 请求示例(Python)
import requests item_id = "DS123456789" access_token = "your_access_token_here" country = "PK" url = f"https://api.daraz.com/product/{item_id}/detail" headers = {"Authorization": f"Bearer {access_token}"} params = {"country": country} response = requests.get(url, headers=headers, params=params) if response.status_code == 200: data = response.json() print("商品标题:", data["title"]) print("当前价格:", data["price"]["value"]) print("库存状态:", data["stock"]["status"]) else: print(f"请求失败,状态码: {response.status_code}")5. 响应数据结构(部分关键字段)
{ "item_id": "DS123456789", "title": "Wireless Bluetooth Headphones", "price": { "value": 1999.00, "currency": "PKR" }, "stock": { "status": "in_stock", "quantity": 50 }, "attributes": [ {"name": "Color", "value": "Black"}, {"name": "Battery Life", "value": "20 hours"} ], "images": [ "https://img.daraz.pk/headphones_1.jpg", "https://img.daraz.pk/headphones_2.jpg" ] }6. 错误处理
常见错误状态码:
401 Unauthorized:认证信息无效404 Not Found:商品ID不存在429 Too Many Requests:请求频率超限
7. 最佳实践建议
- 缓存机制:对频繁访问的商品数据设置本地缓存,减少API调用
- 错误重试:针对
429错误实现指数退避重试策略 - 字段过滤:通过
fields参数指定所需字段,减少网络传输量params = {"country": country, "fields": "title,price,stock"}
8. 注意事项
- 需遵守Daraz API使用条款,禁止高频爬取
- 敏感数据(如
access_token)应使用环境变量存储 - 商品价格可能因促销活动实时变动,建议设置更新频率≥15分钟
提示:完整API文档请参考Daraz开发者门户,不同国家站点可能有参数差异。
通过以上接口,开发者可高效获取Daraz平台的商品核心数据,为电商分析、比价工具等应用提供数据支持。建议在正式集成前进行沙盒环境测试。