Subscription resource


You can use the Subscriptions API to subscribe to specific Twilio events and versions, and manage your subscriptions.

With the Subscriptions API you can:

  • Create new Subscriptions.
  • Fetch a specific Subscription.
  • Fetch a list of Subscriptions.
  • Update a Subscription.
  • Delete a Subscription.

A subscription is comprised of a set of pairs of Event Types and Schema versions that can be modified using the SubscribedEvents API.


Property nameTypeRequiredDescriptionChild properties
account_sidSID<AC>

Optional

The unique SID identifier of the Account.

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

sidSID<DF>

Optional

A 34 character string that uniquely identifies this Subscription.

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

date_createdstring<date-time>

Optional

The date that this Subscription was created, given in ISO 8601 format.


date_updatedstring<date-time>

Optional

The date that this Subscription was updated, given in ISO 8601 format.


descriptionstring

Optional

A human readable description for the Subscription


sink_sidSID<DG>

Optional

The SID of the sink that events selected by this subscription should be sent to. Sink must be active for the subscription to be created.

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

urlstring<uri>

Optional

The URL of this resource.


linksobject<uri-map>

Optional

Contains a dictionary of URL links to nested resources of this Subscription.


receive_events_from_subaccountsboolean

Optional

Receive events from all children accounts in the parent account subscription.


POST https://events.twilio.com/v1/Subscriptions

Make a new Subscription.

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

A human readable description for the Subscription This value should not contain PII.


SinkSidSID<DG>required

The SID of the sink that events selected by this subscription should be sent to. Sink must be active for the subscription to be created.

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

Typesarray[object]required

An array of objects containing the subscribed Event Types


ReceiveEventsFromSubaccountsboolean

Optional

Receive events from all children accounts in the parent account subscription.

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 createSubscription() {
11
const subscription = await client.events.v1.subscriptions.create({
12
description: '"A subscription"',
13
sinkSid: "DGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
types: [
15
{
16
type: "com.twilio.messaging.message.delivered",
17
},
18
{
19
type: "com.twilio.messaging.message.sent",
20
schema_version: 2,
21
},
22
],
23
});
24
25
console.log(subscription.accountSid);
26
}
27
28
createSubscription();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"date_created": "2015-07-30T20:00:00Z",
4
"date_updated": "2015-07-30T20:01:33Z",
5
"sid": "DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"sink_sid": "DGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
7
"description": "\"A subscription\"",
8
"url": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
9
"links": {
10
"subscribed_events": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SubscribedEvents"
11
},
12
"receive_events_from_subaccounts": false
13
}

GET https://events.twilio.com/v1/Subscriptions/{Sid}

Retrieve a specific Subscription using its Subscription ID.

Property nameTypeRequiredPIIDescription
SidSID<DF>required

A 34 character string that uniquely identifies this Subscription.

Pattern: ^DF[0-9a-fA-F]{32}$Min length: 34Max length: 34
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 fetchSubscription() {
11
const subscription = await client.events.v1
12
.subscriptions("DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.fetch();
14
15
console.log(subscription.accountSid);
16
}
17
18
fetchSubscription();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"date_created": "2015-07-30T20:00:00Z",
4
"date_updated": "2015-07-30T20:01:33Z",
5
"sid": "DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"sink_sid": "DGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
7
"description": "A subscription",
8
"url": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
9
"links": {
10
"subscribed_events": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SubscribedEvents"
11
},
12
"receive_events_from_subaccounts": false
13
}

GET https://events.twilio.com/v1/Subscriptions

Retrieve information on all created subscriptions

Property nameTypeRequiredPIIDescription
SinkSidSID<DG>

Optional

The SID of the sink that the list of Subscriptions should be filtered by.

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

PageSizeinteger<int64>

Optional

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

Minimum: 1Maximum: 1000

Pageinteger

Optional

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

Minimum: 0

PageTokenstring

Optional

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 listSubscription() {
11
const subscriptions = await client.events.v1.subscriptions.list({
12
limit: 20,
13
});
14
15
subscriptions.forEach((s) => console.log(s.accountSid));
16
}
17
18
listSubscription();

Output

1
{
2
"subscriptions": [
3
{
4
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"date_created": "2015-07-30T20:00:00Z",
6
"date_updated": "2015-07-30T20:01:33Z",
7
"sid": "DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
8
"sink_sid": "DGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
9
"description": "A subscription",
10
"url": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
11
"links": {
12
"subscribed_events": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SubscribedEvents"
13
},
14
"receive_events_from_subaccounts": false
15
},
16
{
17
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"date_created": "2015-07-30T20:00:00Z",
19
"date_updated": "2015-07-30T20:01:33Z",
20
"sid": "DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
21
"sink_sid": "DGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
22
"description": "Another subscription",
23
"url": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
24
"links": {
25
"subscribed_events": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab/SubscribedEvents"
26
},
27
"receive_events_from_subaccounts": false
28
}
29
],
30
"meta": {
31
"page": 0,
32
"page_size": 20,
33
"first_page_url": "https://events.twilio.com/v1/Subscriptions?PageSize=20&Page=0",
34
"previous_page_url": null,
35
"url": "https://events.twilio.com/v1/Subscriptions?PageSize=20&Page=0",
36
"next_page_url": null,
37
"key": "subscriptions"
38
}
39
}

POST https://events.twilio.com/v1/Subscriptions/{Sid}

Modify an existing Subscription identified by its Subscription ID.

Property nameTypeRequiredPIIDescription
SidSID<DF>required

A 34 character string that uniquely identifies this Subscription.

Pattern: ^DF[0-9a-fA-F]{32}$Min length: 34Max length: 34
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
Descriptionstring

Optional

A human readable description for the Subscription.


SinkSidSID<DG>

Optional

The SID of the sink that events selected by this subscription should be sent to. Sink must be active for the subscription to be created.

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

ReceiveEventsFromSubaccountsboolean

Optional

Receive events from all children accounts in the parent account subscription.

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 updateSubscription() {
11
const subscription = await client.events.v1
12
.subscriptions("DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.update({ description: '"Updated description"' });
14
15
console.log(subscription.accountSid);
16
}
17
18
updateSubscription();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"date_created": "2015-07-30T20:00:00Z",
4
"date_updated": "2020-07-30T20:01:33Z",
5
"sid": "DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"sink_sid": "DGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
7
"description": "\"Updated description\"",
8
"url": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
9
"links": {
10
"subscribed_events": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SubscribedEvents"
11
},
12
"receive_events_from_subaccounts": false
13
}

DELETE https://events.twilio.com/v1/Subscriptions/{Sid}

Remove a Subscription identified by its Subscription ID.

Property nameTypeRequiredPIIDescription
SidSID<DF>required

A 34 character string that uniquely identifies this Subscription.

Pattern: ^DF[0-9a-fA-F]{32}$Min length: 34Max length: 34
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 deleteSubscription() {
11
await client.events.v1
12
.subscriptions("DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.remove();
14
}
15
16
deleteSubscription();