API管理促销活动主要涉及以下几个基础概念:
以下是一个简单的API调用示例,用于创建一个基于时间的促销活动:
import requests
import json
url = "https://api.example.com/promotions"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_ACCESS_TOKEN"
}
data = {
"name": "Summer Sale",
"description": "20% off all items",
"start_date": "2023-07-01T00:00:00Z",
"end_date": "2023-07-31T23:59:59Z",
"discount_rate": 0.20
}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 201:
print("Promotion created successfully!")
else:
print(f"Failed to create promotion: {response.text}")
通过这样的API调用,商家可以轻松地管理和推广他们的促销活动。
领取专属 10元无门槛券
手把手带您无忧上云