要更新库存而不使用 feeds 的 Amazon MWS API,您可以使用下面的代码示例来实现:
首先,您需要使用 MWS API 的库存管理功能。以下是一个示例代码,用于通过 Amazon MWS API 更新库存:
import requests
import xml.etree.ElementTree as ET
# 设置您的 Amazon MWS API 认证信息
access_key = 'your_access_key'
secret_key = 'your_secret_key'
seller_id = 'your_seller_id'
mws_auth_token = 'your_mws_auth_token'
# 设置 API 请求的端点 URL
endpoint = 'https://mws.amazonservices.com'
# 创建一个请求的 payload
payload = {
'AWSAccessKeyId': access_key,
'Action': 'UpdateInventory',
'SellerId': seller_id,
'SignatureVersion': '2',
'SignatureMethod': 'HmacSHA256',
'Version': '2011-10-01',
'Timestamp': datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ'),
'MarketplaceId.Id.1': 'your_marketplace_id', # 您的市场 ID
'Quantity': '10', # 要更新的库存数量
'SellerSKU': 'your_seller_sku', # 您的卖家 SKU
'Signature': ''
}
# 生成签名
payload['Signature'] = generate_signature(payload, secret_key)
# 发送 API 请求
response = requests.post(endpoint, data=payload)
# 解析 API 响应
root = ET.fromstring(response.content)
status = root.find('.//{http://mws.amazonaws.com/doc/2011-10-01/}Status').text
if status == 'Success':
print('库存更新成功!')
else:
print('库存更新失败!')
上述代码中,您需要替换 your_access_key
、your_secret_key
、your_seller_id
、your_mws_auth_token
、your_marketplace_id
和 your_seller_sku
为您自己的认证信息和 SKU。
此代码示例使用 requests 库发送 HTTP 请求,并使用 xml.etree.ElementTree 解析 XML 响应。您还需要实现一个 generate_signature
函数来生成请求的签名。
请注意,此方法仅适用于更新单个 SKU 的库存。如果您要更新多个 SKU 的库存,您可能需要循环调用 API 请求。另外,请确保您已经在 Amazon MWS 卖家中心配置了库存管理功能的权限。