Skip to contentSkip to navigationSkip to topbar
On this page

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.


Subscription Properties

subscription-properties page anchor
Property nameTypeRequiredDescriptionChild properties
account_sidSID<AC>Optional
Not PII

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.


descriptionstringOptional

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.


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

Make a new Subscription.

Request body parameters

request-body-parameters page anchor
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

Typesarrayrequired

An array of objects containing the subscribed Event Types

Create a new SubscriptionLink to code sample: Create a new 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
}

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
}

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

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 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
},
15
{
16
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
17
"date_created": "2015-07-30T20:00:00Z",
18
"date_updated": "2015-07-30T20:01:33Z",
19
"sid": "DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
20
"sink_sid": "DGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"description": "Another subscription",
22
"url": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
23
"links": {
24
"subscribed_events": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab/SubscribedEvents"
25
}
26
}
27
],
28
"meta": {
29
"page": 0,
30
"page_size": 20,
31
"first_page_url": "https://events.twilio.com/v1/Subscriptions?PageSize=20&Page=0",
32
"previous_page_url": null,
33
"url": "https://events.twilio.com/v1/Subscriptions?PageSize=20&Page=0",
34
"next_page_url": null,
35
"key": "subscriptions"
36
}
37
}

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
DescriptionstringOptional

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
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
}

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();

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.