Subscribed Event resource
With this API the user can perform CRUD operations on an Event associated with a Subscription.
With the Subscribed Event API you can:
- Add an existing event type to a subscription
- Get all events associated with a subscription
- Update an event on a subscription
- Delete an event on a subscription
The unique SID identifier of the Account.
^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34The unique SID identifier of the Subscription.
^DF[0-9a-fA-F]{32}$Min length: 34Max length: 34The URL of this resource.
POST https://events.twilio.com/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents
This endpoint adds an existing event type to a particular subscription. It is possible to specify the version of the schema to use for the given event type. Otherwise the last available schema version will be used for the added event type.
The unique SID identifier of the Subscription.
^DF[0-9a-fA-F]{32}$Min length: 34Max length: 34application/x-www-form-urlencoded1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createSubscribedEvent() {11const subscribedEvent = await client.events.v112.subscriptions("DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.subscribedEvents.create({14type: "com.twilio.messaging.message.delivered",15});1617console.log(subscribedEvent.accountSid);18}1920createSubscribedEvent();
Response
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"subscription_sid": "DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"type": "com.twilio.messaging.message.delivered",5"schema_version": 2,6"url": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SubscribedEvents/com.twilio.messaging.message.delivered"7}
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createSubscribedEvent() {11const subscribedEvent = await client.events.v112.subscriptions("DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.subscribedEvents.create({14schemaVersion: 2,15type: "com.twilio.messaging.message.delivered",16});1718console.log(subscribedEvent.accountSid);19}2021createSubscribedEvent();
Response
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"subscription_sid": "DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"type": "com.twilio.messaging.message.delivered",5"schema_version": 2,6"url": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SubscribedEvents/com.twilio.messaging.message.delivered"7}
GET https://events.twilio.com/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents
Get all event types associated with a particular subscription
The unique SID identifier of the Subscription.
^DF[0-9a-fA-F]{32}$Min length: 34Max length: 34How many resources to return in each list page. The default is 50, and the maximum is 1000.
1Maximum: 1000The page token. This is provided by the API.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function listSubscribedEvent() {11const subscribedEvents = await client.events.v112.subscriptions("DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.subscribedEvents.list({ limit: 20 });1415subscribedEvents.forEach((s) => console.log(s.accountSid));16}1718listSubscribedEvent();
Response
1{2"types": [],3"meta": {4"page": 0,5"page_size": 10,6"first_page_url": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SubscribedEvents?PageSize=10&Page=0",7"previous_page_url": null,8"url": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SubscribedEvents?PageSize=10&Page=0",9"next_page_url": null,10"key": "types"11}12}
POST https://events.twilio.com/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}
Updates the event type
application/x-www-form-urlencodedThe schema version that the Subscription should use.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function updateSubscribedEvent() {11const subscribedEvent = await client.events.v112.subscriptions("DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.subscribedEvents("com.twilio.messaging.message.delivered")14.update({ schemaVersion: 1 });1516console.log(subscribedEvent.accountSid);17}1819updateSubscribedEvent();
Response
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"subscription_sid": "DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"type": "com.twilio.messaging.message.delivered",5"schema_version": 1,6"url": "https://events.twilio.com/v1/Subscriptions/DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/SubscribedEvents/com.twilio.messaging.message.delivered"7}
DELETE https://events.twilio.com/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}
Deletes an event type on a subscription.
The unique SID identifier of the Subscription.
^DF[0-9a-fA-F]{32}$Min length: 34Max length: 34Type of event being subscribed to.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function deleteSubscribedEvent() {11await client.events.v112.subscriptions("DFaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.subscribedEvents("com.twilio.messaging.message.delivered")14.remove();15}1617deleteSubscribedEvent();