Skip to main content

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 the token 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’s auth option:
The server reads the token from the 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.
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

  1. Navigate to Settings > API Keys in the Zeplo Dashboard.
  2. Click Create API Key.
  3. Give the key a descriptive name (for example, “Live Chat Bot”).
  4. Select the required permissions (messaging, contacts, campaigns, webhooks).
  5. Copy the key immediately — it is shown only once.

Using the API Key

Never expose your API key in client-side JavaScript. API keys are intended for server-side use. For browser-based applications, use a backend proxy to authenticate the WebSocket connection, or use the session cookie method if the user is logged into the Zeplo Dashboard.

Error Handling

Authentication failures are delivered through the connect_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

Treat your API keys like passwords. Compromised keys give full access to your Zeplo account within the granted permission scope.
  • 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.