Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Session Resource


A Session is a single instance of two individuals communicating. It belongs to a Service and maps two Participants for a Proxy application. Sessions allow you to:

  • Specify a unique identifier relevant to your use case, such as a job ID
  • See whether a given Session is closed or not and the reason it has been closed
  • Control the length of time the Session should be active

Session Properties

session-properties page anchor
Property nameTypeRequiredDescriptionChild properties
sidSID<KC>Optional
Not PII

The unique string that we created to identify the Session resource.

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

service_sidSID<KS>Optional

The SID of the Service the session is associated with.

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

account_sidSID<AC>Optional

The SID of the Account that created the Session resource.

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

date_endedstring<date-time>Optional

The ISO 8601(link takes you to an external page) date when the Session ended.


date_last_interactionstring<date-time>Optional

The ISO 8601(link takes you to an external page) date when the Session last had an interaction.


date_expirystring<date-time>Optional

The ISO 8601(link takes you to an external page) date when the Session should expire. If this is value is present, it overrides the ttl value.


unique_namestringOptional

An application-defined string that uniquely identifies the resource. This value must be 191 characters or fewer in length and be unique. Supports UTF-8 characters. This value should not have PII.


statusenum<string>Optional

The status of the Session. Can be: open, in-progress, closed, failed, or unknown.

Possible values:
openin-progressclosedfailedunknown

closed_reasonstringOptional

The reason the Session ended.


ttlintegerOptional

The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session's last Interaction.

Default: 0

modeenum<string>Optional

The Mode of the Session. Can be: message-only, voice-only, or voice-and-message.

Possible values:
message-onlyvoice-onlyvoice-and-message

date_createdstring<date-time>Optional

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


date_updatedstring<date-time>Optional

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


urlstring<uri>Optional

The absolute URL of the Session resource.


linksobject<uri-map>Optional

The URLs of resources related to the Session.


Create a Session resource

create-a-session-resource page anchor
POST https://proxy.twilio.com/v1/Services/{ServiceSid}/Sessions

Create a new Session.

Path parameters

path-parameters page anchor
Property nameTypeRequiredPIIDescription
ServiceSidSID<KS>required

The SID of the parent Service resource.

Pattern: ^KS[0-9a-fA-F]{32}$Min length: 34Max length: 34
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 191 characters or fewer in length and be unique. This value should not have PII.


DateExpirystring<date-time>Optional

The ISO 8601(link takes you to an external page) date when the Session should expire. If this is value is present, it overrides the ttl value.


TtlintegerOptional

The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session's last Interaction.


Modeenum<string>Optional

The Mode of the Session. Can be: message-only, voice-only, or voice-and-message and the default value is voice-and-message.

Possible values:
message-onlyvoice-onlyvoice-and-message

Statusenum<string>Optional

The initial status of the Session. Can be: open, in-progress, closed, failed, or unknown. The default is open on create.

Possible values:
openin-progressclosedfailedunknown

ParticipantsarrayOptional

The Participant objects to include in the new session.

Create a SessionLink to code sample: Create a Session
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 createSession() {
11
const session = await client.proxy.v1
12
.services("KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.sessions.create();
14
15
console.log(session.sid);
16
}
17
18
createSession();

Output

1
{
2
"service_sid": "KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"status": "open",
4
"unique_name": "Order #1234",
5
"date_started": "2015-07-30T20:00:00Z",
6
"date_ended": "2015-07-30T20:00:00Z",
7
"date_last_interaction": "2015-07-30T20:00:00Z",
8
"date_expiry": "2015-07-30T20:00:00Z",
9
"ttl": 3600,
10
"mode": "voice-and-message",
11
"closed_reason": "",
12
"sid": "KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
13
"date_updated": "2015-07-30T20:00:00Z",
14
"date_created": "2015-07-30T20:00:00Z",
15
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
16
"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
17
"links": {
18
"interactions": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Interactions",
19
"participants": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants"
20
}
21
}

Fetch a Session resource

fetch-a-session-resource page anchor
GET https://proxy.twilio.com/v1/Services/{ServiceSid}/Sessions/{Sid}

Retrieve a single Session.

Property nameTypeRequiredPIIDescription
ServiceSidSID<KS>required

The SID of the parent Service of the resource to fetch.

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

Sidstringrequired

The Twilio-provided string that uniquely identifies the Session 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 fetchSession() {
11
const session = await client.proxy.v1
12
.services("KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.sessions("Sid")
14
.fetch();
15
16
console.log(session.sid);
17
}
18
19
fetchSession();

Output

1
{
2
"service_sid": "KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"status": "open",
4
"unique_name": "Order #1234",
5
"date_started": "2015-07-30T20:00:00Z",
6
"date_ended": "2015-07-30T20:00:00Z",
7
"date_last_interaction": "2015-07-30T20:00:00Z",
8
"date_expiry": "2015-07-30T20:00:00Z",
9
"ttl": 3600,
10
"mode": "voice-and-message",
11
"closed_reason": "",
12
"sid": "Sid",
13
"date_updated": "2015-07-30T20:00:00Z",
14
"date_created": "2015-07-30T20:00:00Z",
15
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
16
"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
17
"links": {
18
"interactions": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Interactions",
19
"participants": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants"
20
}
21
}

Read multiple Session resources

read-multiple-session-resources page anchor
GET https://proxy.twilio.com/v1/Services/{ServiceSid}/Sessions

Retrieve a list of all Sessions for a given Service.

Property nameTypeRequiredPIIDescription
ServiceSidSID<KS>required

The SID of the parent Service of the resource to read.

Pattern: ^KS[0-9a-fA-F]{32}$Min length: 34Max length: 34
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 listSession() {
11
const sessions = await client.proxy.v1
12
.services("KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.sessions.list({ limit: 20 });
14
15
sessions.forEach((s) => console.log(s.sid));
16
}
17
18
listSession();

Output

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

Update a Session resource

update-a-session-resource page anchor
POST https://proxy.twilio.com/v1/Services/{ServiceSid}/Sessions/{Sid}

Post updates to a given Session.

Property nameTypeRequiredPIIDescription
ServiceSidSID<KS>required

The SID of the parent Service of the resource to update.

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

SidSID<KC>required

The Twilio-provided string that uniquely identifies the Session resource to update.

Pattern: ^KC[0-9a-fA-F]{32}$Min length: 34Max length: 34
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
DateExpirystring<date-time>Optional

The ISO 8601(link takes you to an external page) date when the Session should expire. If this is value is present, it overrides the ttl value.


TtlintegerOptional

The time, in seconds, when the session will expire. The time is measured from the last Session create or the Session's last Interaction.


Statusenum<string>Optional

The new status of the resource. Can be: in-progress to re-open a session or closed to close a session.

Possible values:
openin-progressclosedfailedunknown
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 updateSession() {
11
const session = await client.proxy.v1
12
.services("KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.sessions("KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
14
.update({
15
dateExpiry: new Date("2018-07-31 00:00:00"),
16
status: "in-progress",
17
});
18
19
console.log(session.sid);
20
}
21
22
updateSession();

Output

1
{
2
"service_sid": "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"status": "in-progress",
4
"unique_name": "Order #1234",
5
"date_started": "2015-07-30T20:00:00Z",
6
"date_ended": "2015-07-30T20:00:00Z",
7
"date_last_interaction": "2015-07-30T20:00:00Z",
8
"date_expiry": "2018-07-31",
9
"ttl": 3600,
10
"mode": "voice-and-message",
11
"closed_reason": "",
12
"sid": "KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
13
"date_updated": "2015-07-30T20:00:00Z",
14
"date_created": "2015-07-30T20:00:00Z",
15
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
16
"url": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
17
"links": {
18
"interactions": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Interactions",
19
"participants": "https://proxy.twilio.com/v1/Services/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Sessions/KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants"
20
}
21
}

Delete a Session resource

delete-a-session-resource page anchor
DELETE https://proxy.twilio.com/v1/Services/{ServiceSid}/Sessions/{Sid}

Deleting a Session removes it permanently. Related Participants and Interactions will also be deleted.

(error)

Danger

Any Message or Call logs created during interactions for this Sitzung will be deleted automatically after 90 days of the Session being closed, as per our Session retention policy. If you want to delete these resources before then, you must issue DELETE requests for the inbound and outbound resources of all child Interactions directly. Once you have deleted a Session, those resource SIDs will not be discoverable via Proxy.

Property nameTypeRequiredPIIDescription
ServiceSidSID<KS>required

The SID of the parent Service of the resource to delete.

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

SidSID<KC>required

The Twilio-provided string that uniquely identifies the Session resource to delete.

Pattern: ^KC[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 deleteSession() {
11
await client.proxy.v1
12
.services("KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13
.sessions("KCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
14
.remove();
15
}
16
17
deleteSession();

Rate this page: