You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在BestBuy API的viewedUltimatelyBought端点使用in运算符批量查询SKU数据

BestBuy API /products/{sku}/viewedUltimatelyBought 批量查询方案

核心结论

/products/{sku}/viewedUltimatelyBought 端点不支持通过sku in(...)或类似语法进行批量SKU查询——BestBuy API的设计中,这个关联推荐接口是绑定单个SKU的,仅接受路径中传入单个SKU值,所有尝试的批量写法都会被判定为无效查询。

替代优化方案

如果需要获取多个SKU的关联推荐数据,建议通过并发请求来提升效率,同时规避速率限制的影响:

以下是Python实现示例:

import json
import requests
from concurrent.futures import ThreadPoolExecutor

API_KEY = "YourAPIKey"
BASE_URL = "https://api.bestbuy.com/v1/products/{}/viewedUltimatelyBought?apiKey={}"
SKU_LIST = [6559245, 6559246, 6559247]

def fetch_related(sku):
    url = BASE_URL.format(sku, API_KEY)
    response = requests.get(url)
    if response.status_code == 200:
        return {sku: json.loads(response.content)}
    else:
        return {sku: f"Error: {response.status_code}"}

# 控制并发数,避免触发速率限制(根据BestBuy API的限制调整)
with ThreadPoolExecutor(max_workers=5) as executor:
    results = list(executor.map(fetch_related, SKU_LIST))

# 处理结果
for result in results:
    print(result)

注意事项

  • 请根据BestBuy API官方给出的速率限制调整max_workers的数值,避免被限流或封禁。
  • 若API返回分页数据,需在fetch_related函数中添加分页逻辑(比如追加&page=1&pageSize=100参数)。

内容的提问来源于stack exchange,提问作者Saeed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 06:05:06