Authentication

When establishing the connection, ensure you are sending the access token for authentication in the WebSocket handshake process.

1. Request a Login Token

Send a request to this API endpoint:

POST /api/v1/users/request_login

Upon success, you will receive a token sent to your registered email address.

2. Exchange the Login Token for an Access Token

Using the token received via email, send a request to the following endpoint:

POST /api/v1/users/login?login_token=your_login_token

Replace your_login_token with the token sent to your email.

If the request is successful, the response will include your access_token.

note

For more details, visit our API Explorer.

3. Initialize websocket connection

Replace the placeholder values with your access token. Add event listeners to handle connection, messages, errors, and disconnections.

document.addEventListener('DOMContentLoaded', () => {
const socket = new WebSocket(
'wss://savi-api.coinsavi.com/websocket',
[
'actioncable-v1-json',
your_access_token // place your access token here
]
);
socket.onopen = function() {
console.log('Connected to WebSocket!');
};
socket.onmessage = function(event) {
console.log('Received message:', event.data);
};
socket.onerror = function(error) {
console.error('WebSocket error:', error);
};
socket.onclose = function() {
console.log('WebSocket closed');
};
});
note

Use the wss:// protocol for secure WebSocket connections in production.