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 (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.
- Navigate to your Advanced I/O function directory and install the SDK for your runtime.
copy
npm install @zcatalyst/datastreams
Add the following dependency to your pom.xml:
copy
com.zoho.catalyst
datastreams
LATEST
copy
pip install zcatalyst-sdk
- Initialize the SDK in your function code. The SDK automatically resolves project credentials from the execution environment.
copy
const { DataStreams } = require('@zcatalyst/datastreams');
module.exports = async (req, res) => {
const datastreams = new DataStreams();
// ... use datastreams methods
};
copy
import com.zc.component.datastream.ZCDatastream;
ZCDatastream datastream = ZCDatastream.getInstance();
copy
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.
- 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:
copy
const result = await datastreams.publishData('YOUR_CHANNEL_ID', 'Hello, subscribers!');
console.log('Published successfully:', result);
copy
Boolean result = datastream.publishData("YOUR_CHANNEL_ID", "Hello, subscribers!");
System.out.println("Published successfully: " + result);
copy
result = data_streams.publish_data("YOUR_CHANNEL_ID", "Hello, subscribers!")
print("Published successfully:", result)
- For structured data, stringify your JSON before publishing (JavaScript/Java) or pass a dictionary (Python).
copy
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.
copy
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.
copy
# 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 |
Last Updated 2026-10-05 20:43:57 +0530 IST
Yes
No
Send your feedback to us
Skip
Submit