WebSocket Authentication
Every WebSocket connection to Zeplo must be authenticated. This page covers the three authentication methods available and how to handle authentication failures.Authentication Methods
All three methods grant the same level of access. Choose the method that best fits your application’s architecture and security requirements.
Token-Based Authentication
Via Query Parameter
Pass your API key as thetoken query parameter in the connection URL. This is the simplest method and works well for server-side connections.
1
Construct the connection URL
Append your API key as the
token query parameter:2
Connect using Socket.IO
3
Verify the connection
Via Auth Event
For client-side applications where you want to avoid exposing the token in the URL, pass credentials through Socket.IO’sauth option:
auth payload during the handshake.
The
auth option sends the token in the Socket.IO handshake payload rather than in the URL. This prevents the token from appearing in server access logs or browser network panels.Session Cookie Authentication
For dashboard and widget connections where the user is already authenticated via the Zeplo web interface, session cookies are sent automatically by the browser:Session cookie authentication only works for users who are logged into the Zeplo Dashboard. For external integrations, use API key authentication instead.
API Key Authentication
API keys are the recommended method for external integrations, bots, and server-side applications.Creating an API Key
- Navigate to Settings > API Keys in the Zeplo Dashboard.
- Click Create API Key.
- Give the key a descriptive name (for example, “Live Chat Bot”).
- Select the required permissions (messaging, contacts, campaigns, webhooks).
- Copy the key immediately — it is shown only once.
Using the API Key
Error Handling
Authentication failures are delivered through theconnect_error event. Handle these gracefully in your application:
Reconnection with Authentication
Socket.IO reconnects automatically, but you may need to refresh the token on reconnection if you are using short-lived tokens:Using the
auth callback function ensures that a fresh token is provided on every reconnection attempt. This is especially important if your tokens have a short expiration time.Token Security Best Practices
- Store keys in environment variables on your server. Never commit them to source control.
- Use separate keys for development and production environments.
- Rotate keys regularly by creating a new key, updating your application, and then revoking the old key.
- Restrict permissions to only what each integration needs. A bot that only sends messages does not need campaign management permissions.
- Monitor key usage in the Zeplo Dashboard. If you see unexpected activity, revoke the key immediately.
