Skip to contentSkip to navigationSkip to topbar
On this page

Stream Resource


A Stream is a pub-sub primitive that lets you broadcast JSON messages 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.

See also Stream Message for information about the messages in a stream.


Sync Stream properties

sync-stream-properties page anchor
Property nameTypeRequiredDescriptionChild properties
sidSID<TO>Optional
Not PII

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

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

unique_namestringOptional
PII MTL: 30 days

An application-defined string that uniquely identifies the resource. It can be used in place of the resource's sid in the URL to address the resource.


account_sidSID<AC>Optional

The SID of the Account that created the Sync Stream resource.

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

service_sidSID<IS>Optional

The SID of the Sync Service the resource is associated with.

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

urlstring<uri>Optional

The absolute URL of the Message Stream resource.


linksobject<uri-map>Optional

The URLs of the Stream's nested resources.


date_expiresstring<date-time>Optional

The date and time in GMT when the Message Stream expires and will be deleted, specified in ISO 8601(link takes you to an external page) format. If the Message Stream does not expire, this value is null. The Stream might not be deleted immediately after it expires.


date_createdstring<date-time>Optional

The date and time in GMT when the resource was created specified in ISO 8601(link takes you to an external page) format.


date_updatedstring<date-time>Optional

The date and time in GMT when the resource was last updated specified in ISO 8601(link takes you to an external page) format.


created_bystringOptional

The identity of the Stream's creator. If the Stream is created from the client SDK, the value matches the Access Token's identity field. If the Stream was created from the REST API, the value is 'system'.


Create a Sync Stream resource

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

Path parameters

path-parameters page anchor
Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

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

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

An application-defined string that uniquely identifies the resource. This value must be unique within its Service and it can be up to 320 characters long. The unique_name value can be used as an alternative to the sid in the URL path to address the resource.


TtlintegerOptional

How long, in seconds, before the Stream expires and is deleted (time-to-live).

Create a Sync Stream resourceLink to code sample: Create a Sync Stream 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 createSyncStream() {
11
const syncStream = await client.sync.v1
12
.services("ServiceSid")
13
.syncStreams.create();
14
15
console.log(syncStream.sid);
16
}
17
18
createSyncStream();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"created_by": "created_by",
4
"date_expires": "2015-07-30T21:00:00Z",
5
"date_created": "2015-07-30T20:00:00Z",
6
"date_updated": "2015-07-30T20:00:00Z",
7
"links": {
8
"messages": "https://sync.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/TOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages"
9
},
10
"service_sid": "ServiceSid",
11
"sid": "TOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
12
"unique_name": "unique_name",
13
"url": "https://sync.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/TOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
14
}

Fetch a Sync Stream resource

fetch-a-sync-stream-resource page anchor
GET https://sync.twilio.com/v1/Services/{ServiceSid}/Streams/{Sid}

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Sync Service with the Sync Stream resource to fetch.


Sidstringrequired

The SID of the Stream resource to fetch.

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 fetchSyncStream() {
11
const syncStream = await client.sync.v1
12
.services("ServiceSid")
13
.syncStreams("Sid")
14
.fetch();
15
16
console.log(syncStream.sid);
17
}
18
19
fetchSyncStream();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"created_by": "created_by",
4
"date_expires": "2015-07-30T21:00:00Z",
5
"date_created": "2015-07-30T20:00:00Z",
6
"date_updated": "2015-07-30T20:00:00Z",
7
"links": {
8
"messages": "https://sync.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/TOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages"
9
},
10
"service_sid": "ServiceSid",
11
"sid": "Sid",
12
"unique_name": "unique_name",
13
"url": "https://sync.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/TOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
14
}

Read multiple Sync Stream resources

read-multiple-sync-stream-resources page anchor
GET https://sync.twilio.com/v1/Services/{ServiceSid}/Streams

Note: Without a PageSize query parameter, this will return only the first 50 Message Streams. Add a PageSize query parameter to fetch up to 100 items at once. The example has a PageSize value of 20.

See paging for more information.

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Sync Service with the Stream resources to read.

Property nameTypeRequiredPIIDescription
PageSizeintegerOptional

How many resources to return in each list page. The default is 50, and the maximum is 1000.

Minimum: 1Maximum: 1000

PageintegerOptional

The page index. This value is simply for client state.

Minimum: 0

PageTokenstringOptional

The page token. This is provided by the API.

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 listSyncStream() {
11
const syncStreams = await client.sync.v1
12
.services("ServiceSid")
13
.syncStreams.list({ limit: 20 });
14
15
syncStreams.forEach((s) => console.log(s.sid));
16
}
17
18
listSyncStream();

Output

1
{
2
"streams": [],
3
"meta": {
4
"first_page_url": "https://sync.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams?PageSize=50&Page=0",
5
"key": "streams",
6
"next_page_url": null,
7
"page": 0,
8
"page_size": 50,
9
"previous_page_url": null,
10
"url": "https://sync.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams?PageSize=50&Page=0"
11
}
12
}

Update a Sync Stream resource

update-a-sync-stream-resource page anchor
POST https://sync.twilio.com/v1/Services/{ServiceSid}/Streams/{Sid}

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Sync Service with the Sync Stream resource to update.


Sidstringrequired

The SID of the Stream resource to update.

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

How long, in seconds, before the Stream expires and is deleted (time-to-live).

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 updateSyncStream() {
11
const syncStream = await client.sync.v1
12
.services("ServiceSid")
13
.syncStreams("Sid")
14
.update({ ttl: 42 });
15
16
console.log(syncStream.sid);
17
}
18
19
updateSyncStream();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"created_by": "created_by",
4
"date_expires": "2015-07-30T21:00:00Z",
5
"date_created": "2015-07-30T20:00:00Z",
6
"date_updated": "2015-07-30T20:00:00Z",
7
"links": {
8
"messages": "https://sync.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/TOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages"
9
},
10
"service_sid": "ServiceSid",
11
"sid": "Sid",
12
"unique_name": "unique_name",
13
"url": "https://sync.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/TOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
14
}

Delete a Sync Stream resource

delete-a-sync-stream-resource page anchor
DELETE https://sync.twilio.com/v1/Services/{ServiceSid}/Streams/{Sid}

Property nameTypeRequiredPIIDescription
ServiceSidstringrequired

The SID of the Sync Service with the Sync Stream resource to delete.


Sidstringrequired

The SID of the Stream resource to delete.

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 deleteSyncStream() {
11
await client.sync.v1.services("ServiceSid").syncStreams("Sid").remove();
12
}
13
14
deleteSyncStream();

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.