{
"specversion": "1.0",
"type": "com.genesys.custom.event",
"source": "urn:uuid:...",
"id": "evt_123",
"time": "2023-10-27T10:00:00Z",
"data": { "customer_id": "8821" }
}
The POST to /api/v2/eventbridge/events keeps hitting a 409 Conflict. purecloud-platform-client-v2 handles token refresh automatically in Node, so the manual OAuth2 client credentials flow in Python feels messy. We’ve got a batch processor pushing CloudEvents payloads. The requirement’s strict: construct JSON per spec, attach Idempotency-Key header, POST, then poll status. If status isn’t accepted after three checks, the event drops into a local SQLite table.
The 409 happens even when the key is unique. The response body just says duplicate_key_detected. The polling loop works for successes but the conflict breaks the flow. purecloud-platform-client-v2 documentation mentions ingestion takes up to 30 seconds, yet the 409 returns instantly. It feels like the collision check targets the event id field instead of the header. Changing the id in JSON doesn’t help.
- Python 3.10 with
requests - OAuth2 client credentials via
/api/v2/oauth/token - Endpoint:
/api/v2/eventbridge/events - Header:
Idempotency-Key: uuid-v4-generated - Payload follows CloudEvents v1.0
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
"Idempotency-Key": str(uuid.uuid4())
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 409:
cursor.execute("INSERT INTO failed_events VALUES (?, ?, ?)", (payload, headers['Idempotency-Key'], 409))
The token refresh logic checks expiry and requests a new token before the next batch. The manual refresh might introduce a race condition. The SQLite table fills up fast when the 409 loop triggers. The retry logic re-sends the same key which hits 409 again. The CloudEvents validator locally confirms the schema is valid. The source URI structure matches the docs exactly.