--- title: "Publish Data to Channel Using SDK" url: https://docs.catalyst.zoho.com/en/cloud-scale/help/data-streams/implementation/publish-data-sdk/ description: "Publish data to Data Streams channels from server-side Catalyst functions using Java, JavaScript, or Python SDK." last_updated: 2026-10-05T15:13:57Z service: Cloud Scale type: general related_links: - name: "Create a Channel" url: /en/cloud-scale/help/data-streams/implementation/create-channel/ - name: "Key Concepts - Publishing Methods" url: /en/cloud-scale/help/data-streams/key-concepts/#publishing-methods - name: "Advanced I/O Functions" url: /en/serverless/help/functions/advanced-io/ - name: "Java SDK" url: /en/sdk/java/v1/cloud-scale/data-streams/ - name: "JavaScript SDK" url: /en/sdk/javascript/v1/cloudscale/data-streams/ - name: "Python SDK" url: /en/sdk/python/v1/cloud-scale/data-streams/ --- # Publish Data with SDK To publish data to a Data Streams channel using the Catalyst SDK: > **Note:** You must have a [Data Streams channel created](https://docs.catalyst.zoho.com/en/cloud-scale/help/data-streams/implementation/create-channel/) (you'll need the Channel ID) and an Advanced I/O function for publishing. Publishing requires admin-level authentication. The `publishData()` method can only be called from a server-side Catalyst function, not from client/browser applications. 1. Navigate to your Advanced I/O function directory and install the SDK for your runtime. **JavaScript** ```bash npm install @zcatalyst/datastreams ``` **Java** Add the following dependency to your `pom.xml`: ```xml com.zoho.catalyst datastreams LATEST ``` **Python** ```bash pip install zcatalyst-sdk ``` 2. Initialize the SDK in your function code. The SDK automatically resolves project credentials from the execution environment. **JavaScript** ```javascript const { DataStreams } = require('@zcatalyst/datastreams'); module.exports = async (req, res) => { const datastreams = new DataStreams(); // ... use datastreams methods }; ``` **Java** ```java import com.zc.component.datastream.ZCDatastream; ZCDatastream datastream = ZCDatastream.getInstance(); ``` **Python** ```python import zcatalyst_sdk app = zcatalyst_sdk.initialize_app() data_streams = app.datastreams() ``` > **Note:** Do not use `DataStreamsWebSocket` for publishing. That class is for subscribers only. 3. Use the `publishData()` method to send data to your channel. **Method Parameters:**
Parameter Type Description
`channelId` string The unique Channel ID from the console
`data` string (JavaScript/Java) string or dict (Python) The data to publish
**Publish text data:** **JavaScript** ```javascript const result = await datastreams.publishData('YOUR_CHANNEL_ID', 'Hello, subscribers!'); console.log('Published successfully:', result); ``` **Java** ```java Boolean result = datastream.publishData("YOUR_CHANNEL_ID", "Hello, subscribers!"); System.out.println("Published successfully: " + result); ``` **Python** ```python result = data_streams.publish_data("YOUR_CHANNEL_ID", "Hello, subscribers!") print("Published successfully:", result) ``` 4. For structured data, stringify your JSON before publishing (JavaScript/Java) or pass a dictionary (Python). **JavaScript** ```javascript const payload = JSON.stringify({ event: 'temperature_update', value: 23.5, unit: 'celsius', timestamp: Date.now() }); const result = await datastreams.publishData('YOUR_CHANNEL_ID', payload); console.log('Published successfully:', result); ``` > **Note:** Always use `JSON.stringify()`. Passing an object directly will throw a validation error. **Java** ```java String payload = new Gson().toJson(Map.of( "event", "temperature_update", "value", 23.5, "unit", "celsius", "timestamp", System.currentTimeMillis() )); Boolean result = datastream.publishData("YOUR_CHANNEL_ID", payload); System.out.println("Published successfully: " + result); ``` > **Note:** Use `Gson` or another JSON library to convert objects to strings. **Python** ```python # Python SDK accepts dictionaries directly result = data_streams.publish_data("YOUR_CHANNEL_ID", { "event": "temperature_update", "value": 23.5, "unit": "celsius", "timestamp": time.time() }) print("Published successfully:", result) # Or pass a JSON string import json payload = json.dumps({"event": "order_placed", "order_id": 12345}) result = data_streams.publish_data("YOUR_CHANNEL_ID", payload) ``` > **Note:** Python SDK handles both dictionaries and JSON strings. After publishing, data is sent to the Data Streams channel where it is distributed to all active subscribers in real-time. Publishing succeeds even if no subscribers are connected; data is retained for 48 hours. ### Common Errors
Error Cause Solution
`Invalid Channel ID` Wrong or non-existent channel Verify Channel ID in console
`Data must be a string` Passed object instead of string Use `JSON.stringify()` (JavaScript/Java)
`Unauthorized` Called from client-side Move to server-side function
`Channel not found` Channel deleted Recreate channel or update Channel ID