import base64
import hashlib
import hmac
import json
import time
import uuid
import requests
PARTNER_ID = "your_partner_id"
SECRET = "whsec_..." # Sandbox or production secret from Channel3
ENDPOINT = "https://feeds.channel3.ai/v1/sandbox/products"
payload = {
"type": "product.created",
"merchant": {"id": "merchant_123", "domain": "example.com"},
"product": {
"offerId": "SKU12345",
"contentLanguage": "en",
"feedLabel": "US",
"productAttributes": {
"title": "Classic Cotton T-Shirt",
"link": "https://www.example.com/p/SKU12345",
"imageLink": "https://www.example.com/img/SKU12345.jpg",
"availability": "IN_STOCK",
"price": {"amountMicros": "15990000", "currencyCode": "USD"},
},
},
}
raw_body = json.dumps(payload, separators=(",", ":")).encode("utf-8")
webhook_id = f"msg_{uuid.uuid4().hex}"
timestamp = str(int(time.time()))
key = base64.b64decode(SECRET.removeprefix("whsec_"))
signed_payload = f"{webhook_id}.{timestamp}.".encode("utf-8") + raw_body
digest = hmac.new(key, signed_payload, hashlib.sha256).digest()
signature = f"v1,{base64.b64encode(digest).decode('utf-8')}"
response = requests.post(
ENDPOINT,
data=raw_body,
headers={
"Content-Type": "application/json",
"X-Channel3-Partner-Id": PARTNER_ID,
"webhook-id": webhook_id,
"webhook-timestamp": timestamp,
"webhook-signature": signature,
},
)
print(response.status_code, response.json())