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
Resource properties
sidtype: SID<KC>Not PII

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


account_sidtype: SID<AC>Not PII

The SID of the Account(link takes you to an external page) that created the Session resource.


date_startedtype: string<DATE TIME>Not PII

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


date_endedtype: string<DATE TIME>Not PII

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


date_last_interactiontype: string<DATE TIME>Not PII

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


date_expirytype: string<DATE TIME>Not PII

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_nametype: stringNot PII

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.


statustype: enum<STRING>Not PII

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

Possible values:
openin-progressclosedfailedunknown

closed_reasontype: stringNot PII

The reason the Session ended.


ttltype: integerNot PII

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


modetype: enum<STRING>Not PII

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

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

date_createdtype: string<DATE TIME>Not PII

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


date_updatedtype: string<DATE TIME>Not PII

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


urltype: string<URI>Not PII

The absolute URL of the Session resource.


linkstype: object<URI MAP>Not PII

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.

Parameters

create-parameters page anchor
URI parameters
ServiceSidtype: SID<KS>Not PII
Path Parameter

The SID of the parent Service(link takes you to an external page) resource.


Request body parameters
UniqueNametype: stringNot PII

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.


DateExpirytype: string<DATE TIME>Not PII

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.


Ttltype: integerNot PII

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


Modetype: enum<STRING>Not PII

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

Statustype: enum<STRING>Not PII

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

Participantstype: arrayNot PII

The Participant objects to include in the new session.

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_11
// Download the helper library from https://www.twilio.com/docs/node/install
_11
// Find your Account SID and Auth Token at twilio.com/console
_11
// and set the environment variables. See http://twil.io/secure
_11
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_11
const authToken = process.env.TWILIO_AUTH_TOKEN;
_11
const client = require('twilio')(accountSid, authToken);
_11
_11
client.proxy.v1.services('KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.sessions
_11
.create()
_11
.then(session => console.log(session.sid));

Output

_21
{
_21
"service_sid": "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
"status": "open",
_21
"unique_name": "Order #1234",
_21
"date_started": "2015-07-30T20:00:00Z",
_21
"date_ended": "2015-07-30T20:00:00Z",
_21
"date_last_interaction": "2015-07-30T20:00:00Z",
_21
"date_expiry": "2015-07-30T20:00:00Z",
_21
"ttl": 3600,
_21
"mode": "voice-and-message",
_21
"closed_reason": "",
_21
"sid": "KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
"date_updated": "2015-07-30T20:00:00Z",
_21
"date_created": "2015-07-30T20:00:00Z",
_21
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
"url": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions/KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
"links": {
_21
"interactions": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions/KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Interactions",
_21
"participants": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions/KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Participants"
_21
}
_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.

URI parameters
ServiceSidtype: SID<KS>Not PII
Path Parameter

The SID of the parent Service(link takes you to an external page) of the resource to fetch.


Sidtype: stringNot PII
Path Parameter

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

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_11
// Download the helper library from https://www.twilio.com/docs/node/install
_11
// Find your Account SID and Auth Token at twilio.com/console
_11
// and set the environment variables. See http://twil.io/secure
_11
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_11
const authToken = process.env.TWILIO_AUTH_TOKEN;
_11
const client = require('twilio')(accountSid, authToken);
_11
_11
client.proxy.v1.services('KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.sessions('KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.fetch()
_11
.then(session => console.log(session.uniqueName));

Output

_21
{
_21
"service_sid": "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
"status": "open",
_21
"unique_name": "Order #1234",
_21
"date_started": "2015-07-30T20:00:00Z",
_21
"date_ended": "2015-07-30T20:00:00Z",
_21
"date_last_interaction": "2015-07-30T20:00:00Z",
_21
"date_expiry": "2015-07-30T20:00:00Z",
_21
"ttl": 3600,
_21
"mode": "voice-and-message",
_21
"closed_reason": "",
_21
"sid": "KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
"date_updated": "2015-07-30T20:00:00Z",
_21
"date_created": "2015-07-30T20:00:00Z",
_21
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
"url": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions/KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
"links": {
_21
"interactions": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions/KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Interactions",
_21
"participants": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions/KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Participants"
_21
}
_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.

URI parameters
ServiceSidtype: SID<KS>Not PII
Path Parameter

The SID of the parent Service(link takes you to an external page) of the resource to read.


PageSizetype: integerNot PII
Query Parameter

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


Pagetype: integerNot PII
Query Parameter

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


PageTokentype: stringNot PII
Query Parameter

The page token. This is provided by the API.

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_11
// Download the helper library from https://www.twilio.com/docs/node/install
_11
// Find your Account SID and Auth Token at twilio.com/console
_11
// and set the environment variables. See http://twil.io/secure
_11
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_11
const authToken = process.env.TWILIO_AUTH_TOKEN;
_11
const client = require('twilio')(accountSid, authToken);
_11
_11
client.proxy.v1.services('KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.sessions
_11
.list({limit: 20})
_11
.then(sessions => sessions.forEach(s => console.log(s.sid)));

Output

_12
{
_12
"sessions": [],
_12
"meta": {
_12
"previous_page_url": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions?PageSize=50&Page=0",
_12
"next_page_url": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions?PageSize=50&Page=1",
_12
"url": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions?PageSize=50&Page=0",
_12
"page": 0,
_12
"first_page_url": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions?PageSize=50&Page=0",
_12
"page_size": 50,
_12
"key": "sessions"
_12
}
_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.

URI parameters
ServiceSidtype: SID<KS>Not PII
Path Parameter

The SID of the parent Service(link takes you to an external page) of the resource to update.


Sidtype: SID<KC>Not PII
Path Parameter

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


Request body parameters
DateExpirytype: string<DATE TIME>Not PII

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.


Ttltype: integerNot PII

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


Statustype: enum<STRING>Not PII

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
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_14
// Download the helper library from https://www.twilio.com/docs/node/install
_14
// Find your Account SID and Auth Token at twilio.com/console
_14
// and set the environment variables. See http://twil.io/secure
_14
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_14
const authToken = process.env.TWILIO_AUTH_TOKEN;
_14
const client = require('twilio')(accountSid, authToken);
_14
_14
client.proxy.v1.services('KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_14
.sessions('KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_14
.update({
_14
dateExpiry: new Date(Date.UTC(2018, 6, 31, 0, 0, 0)),
_14
status: 'in-progress'
_14
})
_14
.then(session => console.log(session.uniqueName));

Output

_21
{
_21
"service_sid": "KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
"status": "in-progress",
_21
"unique_name": "Order #1234",
_21
"date_started": "2015-07-30T20:00:00Z",
_21
"date_ended": "2015-07-30T20:00:00Z",
_21
"date_last_interaction": "2015-07-30T20:00:00Z",
_21
"date_expiry": "2018-07-31",
_21
"ttl": 3600,
_21
"mode": "voice-and-message",
_21
"closed_reason": "",
_21
"sid": "KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
"date_updated": "2015-07-30T20:00:00Z",
_21
"date_created": "2015-07-30T20:00:00Z",
_21
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
"url": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions/KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_21
"links": {
_21
"interactions": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions/KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Interactions",
_21
"participants": "https://proxy.twilio.com/v1/Services/KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sessions/KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Participants"
_21
}
_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 Session 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.

URI parameters
ServiceSidtype: SID<KS>Not PII
Path Parameter

The SID of the parent Service(link takes you to an external page) of the resource to delete.


Sidtype: SID<KC>Not PII
Path Parameter

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

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.proxy.v1.services('KSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_10
.sessions('KCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_10
.remove();


Rate this page: