We’re trying to pull real-time queue metrics from the CXone Notification API and push them straight into a Kafka topic. The setup uses a basic Node.js consumer that subscribes to wss://api.mypurecloud.com/api/v2/analytics/notifications. We handle the OAuth token refresh manually since the official SDK doesn’t play nice with our internal proxy. The initial handshake works fine. Here’s how we’re wiring the listener step by step. First, we grab the bearer token from our vault. Next, we open the WebSocket with that header attached. Then we parse the incoming buffer and filter for QUEUE_METRICS. Finally, we shove the payload into the broker.
const ws = new WebSocket(url, { headers: { Authorization: Bearer ${token} } }); ws.on(‘message’, (data) => { const event = JSON.parse(data); if (event.type === ‘QUEUE_METRICS’) { kafkaProducer.send({ topic: ‘cxone-metrics’, messages: [{ value: event }] }); } });
We keep getting a 1006 abnormal closure right after the token expires. The docs claim the server should push a 401 Unauthorized frame to trigger a reconnect, but we’re just seeing the socket hard close. Tried adding a custom ping/pong handler to keep the connection alive. The platform still drops it anyway. The payload structure looks correct on the first pass. All the queueId and handleCount fields map properly into the broker. Maybe the Authorization header needs to be refreshed in the WebSocket upgrade request instead of relying on the initial token. We’ve been spinning on this for a couple of days. The Kafka side is fine. It’s just the upstream stream that keeps choking. The server isn’t sending the proper auth challenge frame before cutting the connection.