--- title: "Generate Token Pair" url: https://docs.catalyst.zoho.com/en/sdk/nodejs/v2/cloud-scale/data-streams/generate-token-pair/ description: "This page describes the methods to generate WebSocket access tokens for subscribers in your Node.js application with sample code snippets." last_updated: 2026-08-13T11:41:55Z service: Cloud Scale type: general related_links: - name: "Get Token Pair - API" url: /en/api/code-reference/cloud-scale/data-streams/get-token-pair - name: "Data Streams" url: /en/cloud-scale/help/data-streams/introduction --- # Generate Token Pair Before a client can subscribe to a [Data Streams](https://docs.catalyst.zoho.com/en/cloud-scale/help/data-streams/introduction/) channel, it must obtain a token pair to authenticate the WebSocket connection. The token pair can be generated using either a user ID or a connection name. You can generate the token pair in two ways as described in this section. The `datastreams` reference used in the code below is the [component instance](https://docs.catalyst.zoho.com/en/sdk/nodejs/v2/cloud-scale/data-streams/get-component-instance) created earlier. ### Get Token Pair using Connection Name You can generate a token pair by passing the channel ID and a connection name to the `getTokenPair()` method. The connection name is a custom identifier for the subscriber connection. The promise returned here will be resolved to a token pair object. **Parameters Used**
Parameter Name Data Type Definition
`channelId` **String** A **Mandatory** parameter. Holds the unique ID of the channel.
`connectionName` **String** A **Mandatory** parameter. Holds the custom identifier for the subscriber connection.
```javascript //Generate token pair using connection name const response = await datastreams.getTokenPair(CRICKET_CHANNEL_ID, { connectionName: "cricketScoreUpdates" }); ``` ### Get Token Pair using User ID Alternatively, you can generate a token pair by passing the channel ID and the user ID to the `getTokenPair()` method. The user ID represents the unique identifier of the application user who is subscribing to the channel. The promise returned here will be resolved to a token pair object. **Parameters Used**
Parameter Name Data Type Definition
`channelId` **String** A **Mandatory** parameter. Holds the unique ID of the channel.
`userId` **String** A **Mandatory** parameter. Holds the unique ID of the user subscribing to the channel.
```javascript //Generate token pair using user ID const response = await datastreams.getTokenPair(CRICKET_CHANNEL_ID, { userId: "userId" }); ```