Skip to contentSkip to navigationSkip to topbar
On this page

Stream Message Resource


A Stream Message is a JSON message that can be sent at a high rate to an elastic group of subscribers.

  • Messages are ephemeral - they can be published (created), but they cannot be queried, updated or deleted
  • The maximum Message payload size as serialized JSON is 4KB.
  • The maximum Message publishing rate per Stream is 30 per second.
  • Message delivery to remote endpoints is not guaranteed.
  • Messages may be received by remote endpoints in a different order than they were published.

Stream Message properties

stream-message-properties page anchor
Property nameTypeRequiredDescriptionChild properties
sidSID<TZ>Optional
Not PII

The unique string that we created to identify the Stream Message resource.

Pattern: ^TZ[0-9a-fA-F]{32}$Min length: 34Max length: 34

dataobjectOptional
PII MTL: 0 days

An arbitrary, schema-less object that contains the Stream Message body. Can be up to 4 KiB in length.


Create a Stream Message resource

create-a-stream-message-resource page anchor
POST https://sync.twilio.com/v1/Services/{ServiceSid}/Streams/{StreamSid}/Messages

Publishes a new message to the Stream. The message contains an arbitrary JSON object that is serialized and percent-encoded as a POST parameter.

Path parameters

path-parameters page anchor
Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Sync Service to create the new Stream Message in.


StreamSidstringrequired

The SID of the Sync Stream to create the new Stream Message resource for.

Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
Dataobjectrequired

A JSON string that represents an arbitrary, schema-less object that makes up the Stream Message body. Can be up to 4 KiB in length.

Create a Stream Message resourceLink to code sample: Create a Stream Message resource
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createStreamMessage() {
11
const streamMessage = await client.sync.v1
12
.services("ServiceSid")
13
.syncStreams("StreamSid")
14
.streamMessages.create({ data: {} });
15
16
console.log(streamMessage.sid);
17
}
18
19
createStreamMessage();

Output

1
{
2
"sid": "TZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"data": {}
4
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.