Price-drop sale videos for 200 SKUs: two bulk queues, one key each

A bulk queue holds at most 100 items. For 200 marked-down SKUs, send two queues, give each its own Idempotency-Key, and track both queue ids yourself.

3 min readSume
All posts

You cannot put 200 items in one Sume bulk queue. The items array takes 1 to 100 entries, so a 200-SKU markdown event is two POST .../bulk-runs calls, each with its own Idempotency-Key.

Split the list, not the Format

Both queues call the same Format. The docs say the scope of an idempotency key is one Format, and that a replay of a spent key returns 202 with the old queue. If you reuse one key for the second half with a different payload, the API answers 409 idempotency_conflict and details.queue_id names the first queue. So mint one key per chunk, and store it next to the chunk before you send.

import os, uuid, requests

API = "https://api.sume.com/v1/formats/sume/product-commercial/bulk-runs"
H = {"Authorization": "Bearer " + os.environ["SUME_API_KEY"]}

def submit(rows):
    items = [{"instruction": "Price drop announcement",
              "input": {"sku": r["sku"], "was": r["was"], "now": r["now"]}}
             for r in rows]
    key = str(uuid.uuid4())  # persist this with the chunk
    res = requests.post(API, headers={**H, "Idempotency-Key": key},
                        json={"concurrency": 8, "items": items}, timeout=30)
    res.raise_for_status()
    return res.json()["data"]["id"]

# rows: your 200 marked-down products
rows = [{"sku": f"SKU-{i}", "was": 40, "now": 28} for i in range(200)]
queues = [submit(rows[i:i + 100]) for i in range(0, len(rows), 100)]
print(queues)

What to record

  • The queue id and the key for each chunk, so a retry after a timeout cannot start a second batch.
  • The chunk's SKU order. Item index is the zero-based position in the array you sent, and the queue keeps that order.
  • The Format slug. Check it with GET /v1/formats/sume/{slug} before the sale starts; an unlisted slug answers 404 format_not_found.

Each chunk finishes on its own

Queue completed only means every item is terminal. Read counts.failed and counts.canceled for both queues before you tell merchandising the sale assets are ready. Each create spends one write from your rate-limit budget, so two queues cost two writes, not 200.

Sources

Related posts

More in Formats

All Formats posts

Written by Sume