Building a custom chat UI to bypass the default widget styling. Trying to connect to the Guest API WebSocket endpoint directly. Got the bearer token from the OAuth service, but the initial handshake keeps dropping with a 403 Forbidden error.
Here’s the fetch call I’m using to get the token:
const tokenRes = await fetch('https://{{organization}}.mypurecloud.com/api/v2/oauth/token', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'grant_type=client_credentials&client_id={{clientId}}&client_secret={{clientSecret}}'
});
Then I grab the token and try to open the socket:
const ws = new WebSocket(`wss://{{organization}}.mypurecloud.com/api/v2/guests/conversations/websockets`);
ws.onopen = () => console.log('Connected');
ws.onerror = (e) => console.error('WS Error', e);
The error handler fires immediately. Checked the token in Postman and it works fine for REST calls. Is there a specific scope I’m missing for the WebSocket connection? The docs are pretty light on the auth flow for this specific endpoint.