淘宝商品详情数据API接口及JSON格式优惠券数据参考
一、核心API接口说明
淘宝开放平台提供以下关键接口获取商品详情及优惠券信息:
-
taobao.item.get
- 功能:获取商品基础信息(标题、价格、库存等)及部分促销信息。
- 优惠券字段:部分版本可能返回优惠券ID或活动ID,但需结合其他接口获取完整信息。
-
taobao.tbk.item.info.get
(淘宝客API)-
功能:专为推广场景设计,返回商品优惠信息(优惠券链接、面额、使用条件等)。
-
关键字段:
coupon_click_url
:优惠券领取链接coupon_info
:优惠券面额及使用条件(如“满100减20”)coupon_start_time
/coupon_end_time
:有效期
-
-
taobao.promotion.detail.get
(需申请权限)- 功能:获取商品所有促销活动详情,包括优惠券、满减、赠品等。
二、JSON格式优惠券数据示例,API接口测试
以下为调用taobao.tbk.item.info.get
接口返回的优惠券信息示例:
json
{
"tbk_item_info_get_response": {
"results": {
"n_tbk_item": [
{
"num_iid": "650350828305",
"title": "夏季新款连衣裙女中长款",
"coupon_click_url": "https://uland.taobao.com/coupon/edetail?e=xxx",
"coupon_info": "满200元减50元",
"coupon_start_time": "2025-06-01 00:00:00",
"coupon_end_time": "2025-06-30 23:59:59",
"zk_final_price": "159.00", // 券后价
"user_type": 1, // 1=天猫, 0=淘宝
"provcity": "浙江 杭州"
}
]
},
"request_id": "abcdef123456"
}
}
三、关键字段解析
字段名 | 类型 | 说明 |
---|---|---|
coupon_click_url | String | 优惠券领取链接(需拼接用户PID) |
coupon_info | String | 优惠券规则(如“满300减100”) |
coupon_start_time | String | 优惠券生效时间(格式:YYYY-MM-DD HH:mm:ss) |
coupon_end_time | String | 优惠券失效时间 |
zk_final_price | String | 商品券后价(原价-优惠券面额) |
四、Python调用示例
python
import requests
import hashlib
import time
class TaobaoCouponAPI:
def __init__(self, app_key, app_secret):
self.app_key = app_key
self.app_secret = app_secret
self.gateway = "http://gw.api.taobao.com/router/rest"
def _generate_sign(self, params):
sorted_params = sorted(params.items(), key=lambda x: x[0])
string_to_sign = self.app_secret
for k, v in sorted_params:
string_to_sign += f"{k}{v}"
string_to_sign += self.app_secret
return hashlib.md5(string_to_sign.encode('utf-8')).hexdigest().upper()
def get_coupon_info(self, item_id, adzone_id):
params = {
'method': 'taobao.tbk.item.info.get',
'app_key': self.app_key,
'timestamp': time.strftime("%Y-%m-%d %H:%M:%S"),
'format': 'json',
'v': '2.0',
'sign_method': 'md5',
'num_iids': item_id,
'adzone_id': adzone_id,
'platform': '2',
'fields': 'num_iid,title,coupon_click_url,coupon_info,coupon_start_time,coupon_end_time,zk_final_price'
}
params['sign'] = self._generate_sign(params)
response = requests.get(self.gateway, params=params)
return response.json()
# 使用示例
api = TaobaoCouponAPI('your_app_key', 'your_app_secret')
coupon_data = api.get_coupon_info('650350828305', '12345678')
print(coupon_data)