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

Conversation Resource


A Conversation is a unique message thread that contains Participants and the Messages they have sent.

(error)

Do not use Personally Identifiable Information (PII) for the friendlyName field

Avoid using a person's name, home address, email, phone number, or other PII in the friendlyName field. Use some form of pseudonymized identifier, instead.

You can learn more about how we process your data in our privacy policy.(link takes you to an external page)


API Base URL

api-base-url page anchor

All URLs in the reference documentation use the following base URL:


_10
https://conversations.twilio.com/v1

Using the shortened base URL

using-the-shortened-base-url page anchor

Using the REST API, you can interact with Conversation resources in the default Conversation Service instance via a "shortened" URL that does not include the Conversation Service instance SID ("ISXXX..."). If you are only using one Conversation Service (the default), you do not need to include the Conversation Service SID in your URL, e.g.


_10
GET /v1/Conversations

For Conversations applications that build on more than one Conversation Service instance, you will need to specify the Conversation Service SID in the REST API call:


_10
GET /v1/Services/ISxx/Conversations


Property nameTypePIIDescription
account_sidSID<AC>
Not PII

The unique ID of the Account responsible for this conversation.

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

chat_service_sidSID<IS>

The unique ID of the Conversation Service this conversation belongs to.

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

messaging_service_sidSID<MG>

The unique ID of the Messaging Service this conversation belongs to.

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

sidSID<CH>

A 34 character string that uniquely identifies this resource.

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

friendly_namestring
PII MTL: 30 days

The human-readable name of this conversation, limited to 256 characters. Optional.


unique_namestring

An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's sid in the URL.


attributesstring

An optional string metadata field you can use to store any data you wish. The string value must contain structurally valid JSON if specified. Note that if the attributes are not set "{}" will be returned.


stateenum<string>

Current state of this conversation. Can be either active, inactive or closed and defaults to active

Possible values:
inactiveactiveclosed

date_createdstring<date-time>

The date that this resource was created.


date_updatedstring<date-time>

The date that this resource was last updated.


timersobject

Timer date values representing state update for this conversation.


urlstring<uri>

An absolute API resource URL for this conversation.


linksobject<uri-map>

Contains absolute URLs to access the participants, messages and webhooks of this conversation.


bindingsnull

Create a Conversation resource

create-a-conversation-resource page anchor
POST https://conversations.twilio.com/v1/Conversations

Property nameTypeRequiredPIIDescription
X-Twilio-Webhook-Enabledenum<string>Optional

The X-Twilio-Webhook-Enabled HTTP request header

Possible values:
truefalse
Property nameTypeRequiredPIIDescription
FriendlyNamestringOptional

The human-readable name of this conversation, limited to 256 characters. Optional.


UniqueNamestringOptional

An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's sid in the URL.


DateCreatedstring<date-time>Optional

The date that this resource was created.


DateUpdatedstring<date-time>Optional

The date that this resource was last updated.


MessagingServiceSidSID<MG>Optional

The unique ID of the Messaging Service this conversation belongs to.

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

AttributesstringOptional

An optional string metadata field you can use to store any data you wish. The string value must contain structurally valid JSON if specified. Note that if the attributes are not set "{}" will be returned.


Stateenum<string>Optional

Current state of this conversation. Can be either active, inactive or closed and defaults to active

Possible values:
inactiveactiveclosed

Timers.InactivestringOptional

ISO8601 duration when conversation will be switched to inactive state. Minimum value for this timer is 1 minute.


Timers.ClosedstringOptional

ISO8601 duration when conversation will be switched to closed state. Minimum value for this timer is 10 minutes.


Bindings.Email.AddressstringOptional

The default email address that will be used when sending outbound emails in this conversation.


Bindings.Email.NamestringOptional

The default name that will be used when sending outbound emails in this conversation.

Create Conversation

create-conversation page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function createConversation() {
_18
const conversation = await client.conversations.v1.conversations.create({
_18
friendlyName: "Friendly Conversation",
_18
});
_18
_18
console.log(conversation.sid);
_18
}
_18
_18
createConversation();

Output

_23
{
_23
"sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_23
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_23
"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_23
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_23
"friendly_name": "Friendly Conversation",
_23
"unique_name": "unique_name",
_23
"attributes": "{ \"topic\": \"feedback\" }",
_23
"date_created": "2015-12-16T22:18:37Z",
_23
"date_updated": "2015-12-16T22:18:38Z",
_23
"state": "inactive",
_23
"timers": {
_23
"date_inactive": "2015-12-16T22:19:38Z",
_23
"date_closed": "2015-12-16T22:28:38Z"
_23
},
_23
"bindings": {},
_23
"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_23
"links": {
_23
"participants": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants",
_23
"messages": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages",
_23
"webhooks": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks"
_23
}
_23
}


Fetch a Conversation resource

fetch-a-conversation-resource page anchor
GET https://conversations.twilio.com/v1/Conversations/{Sid}

You can fetch a Conversation by providing your account credentials and the conversation SID (provided when the Conversation is created).

The most valuable part of the Conversation resource itself is the attributes key, which includes metadata attached to the conversation from the moment of its creation.

The other relevant parts of a Conversation include its Participants (the entities who are currently conversing) and the Messages they've sent. Both of these are linked directly from the top-level url key.

Property nameTypeRequiredPIIDescription
Sidstringrequired

A 34 character string that uniquely identifies this resource. Can also be the unique_name of the Conversation.

Fetch Conversation by SID

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

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function fetchConversation() {
_18
const conversation = await client.conversations.v1
_18
.conversations("CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_18
.fetch();
_18
_18
console.log(conversation.accountSid);
_18
}
_18
_18
fetchConversation();

Output

_23
{
_23
"sid": "CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_23
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_23
"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_23
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_23
"friendly_name": "My First Conversation",
_23
"unique_name": "first_conversation",
_23
"attributes": "{ \"topic\": \"feedback\" }",
_23
"date_created": "2015-12-16T22:18:37Z",
_23
"date_updated": "2015-12-16T22:18:38Z",
_23
"state": "active",
_23
"timers": {
_23
"date_inactive": "2015-12-16T22:19:38Z",
_23
"date_closed": "2015-12-16T22:28:38Z"
_23
},
_23
"bindings": {},
_23
"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_23
"links": {
_23
"participants": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants",
_23
"messages": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages",
_23
"webhooks": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks"
_23
}
_23
}


Read multiple Conversation resources

read-multiple-conversation-resources page anchor
GET https://conversations.twilio.com/v1/Conversations

Returns a list of conversations sorted by recent message activity.

Property nameTypeRequiredPIIDescription
StartDatestringOptional

Specifies the beginning of the date range for filtering Conversations based on their creation date. Conversations that were created on or after this date will be included in the results. The date must be in ISO8601 format, specifically starting at the beginning of the specified date (YYYY-MM-DDT00:00:00Z), for precise filtering. This parameter can be combined with other filters. If this filter is used, the returned list is sorted by latest conversation creation date in descending order.


EndDatestringOptional

Defines the end of the date range for filtering conversations by their creation date. Only conversations that were created on or before this date will appear in the results. The date must be in ISO8601 format, specifically capturing up to the end of the specified date (YYYY-MM-DDT23:59:59Z), to ensure that conversations from the entire end day are included. This parameter can be combined with other filters. If this filter is used, the returned list is sorted by latest conversation creation date in descending order.


Stateenum<string>Optional

State for sorting and filtering list of Conversations. Can be active, inactive or closed

Possible values:
inactiveactiveclosed

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.

Read multiple Conversation resources

read-multiple-conversation-resources-1 page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function listConversation() {
_18
const conversations = await client.conversations.v1.conversations.list({
_18
limit: 20,
_18
});
_18
_18
conversations.forEach((c) => console.log(c.accountSid));
_18
}
_18
_18
listConversation();

Output

_36
{
_36
"conversations": [
_36
{
_36
"sid": "CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_36
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_36
"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_36
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_36
"friendly_name": "Home Repair Visit",
_36
"unique_name": null,
_36
"attributes": "{ \"topic\": \"feedback\" }",
_36
"date_created": "2015-12-16T22:18:37Z",
_36
"date_updated": "2015-12-16T22:18:38Z",
_36
"state": "active",
_36
"timers": {
_36
"date_inactive": "2015-12-16T22:19:38Z",
_36
"date_closed": "2015-12-16T22:28:38Z"
_36
},
_36
"bindings": {},
_36
"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_36
"links": {
_36
"participants": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants",
_36
"messages": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages",
_36
"webhooks": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks"
_36
}
_36
}
_36
],
_36
"meta": {
_36
"page": 0,
_36
"page_size": 50,
_36
"first_page_url": "https://conversations.twilio.com/v1/Conversations?PageSize=50&Page=0",
_36
"previous_page_url": null,
_36
"url": "https://conversations.twilio.com/v1/Conversations?PageSize=50&Page=0",
_36
"next_page_url": null,
_36
"key": "conversations"
_36
}
_36
}


POST https://conversations.twilio.com/v1/Conversations/{Sid}

The core definition of any Conversation can be modified on the fly. Update a Conversation to attach metadata that you extract on the fly (e.g. "customer-loyalty-status": "gold", or "aml-risk-level": "heightened"), or to correct mistakes manually.

Property nameTypeRequiredPIIDescription
X-Twilio-Webhook-Enabledenum<string>Optional

The X-Twilio-Webhook-Enabled HTTP request header

Possible values:
truefalse
Property nameTypeRequiredPIIDescription
Sidstringrequired

A 34 character string that uniquely identifies this resource. Can also be the unique_name of the Conversation.

Property nameTypeRequiredPIIDescription
FriendlyNamestringOptional

The human-readable name of this conversation, limited to 256 characters. Optional.


DateCreatedstring<date-time>Optional

The date that this resource was created.


DateUpdatedstring<date-time>Optional

The date that this resource was last updated.


AttributesstringOptional

An optional string metadata field you can use to store any data you wish. The string value must contain structurally valid JSON if specified. Note that if the attributes are not set "{}" will be returned.


MessagingServiceSidSID<MG>Optional

The unique ID of the Messaging Service this conversation belongs to.

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

Stateenum<string>Optional

Current state of this conversation. Can be either active, inactive or closed and defaults to active

Possible values:
inactiveactiveclosed

Timers.InactivestringOptional

ISO8601 duration when conversation will be switched to inactive state. Minimum value for this timer is 1 minute.


Timers.ClosedstringOptional

ISO8601 duration when conversation will be switched to closed state. Minimum value for this timer is 10 minutes.


UniqueNamestringOptional

An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's sid in the URL.


Bindings.Email.AddressstringOptional

The default email address that will be used when sending outbound emails in this conversation.


Bindings.Email.NamestringOptional

The default name that will be used when sending outbound emails in this conversation.

Update a Conversation's property

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

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function updateConversation() {
_18
const conversation = await client.conversations.v1
_18
.conversations("Sid")
_18
.update({ friendlyName: "Important Customer Question" });
_18
_18
console.log(conversation.friendlyName);
_18
}
_18
_18
updateConversation();

Output

_23
{
_23
"sid": "Sid",
_23
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_23
"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_23
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
_23
"friendly_name": "Important Customer Question",
_23
"unique_name": "unique_name",
_23
"attributes": "{ \"topic\": \"feedback\" }",
_23
"date_created": "2015-12-16T22:18:37Z",
_23
"date_updated": "2015-12-16T22:18:38Z",
_23
"state": "inactive",
_23
"timers": {
_23
"date_inactive": "2015-12-16T22:19:38Z",
_23
"date_closed": "2015-12-16T22:28:38Z"
_23
},
_23
"bindings": {},
_23
"url": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_23
"links": {
_23
"participants": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Participants",
_23
"messages": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages",
_23
"webhooks": "https://conversations.twilio.com/v1/Conversations/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks"
_23
}
_23
}


Delete a Conversation resource

delete-a-conversation-resource page anchor
DELETE https://conversations.twilio.com/v1/Conversations/{Sid}

Property nameTypeRequiredPIIDescription
X-Twilio-Webhook-Enabledenum<string>Optional

The X-Twilio-Webhook-Enabled HTTP request header

Possible values:
truefalse
Property nameTypeRequiredPIIDescription
Sidstringrequired

A 34 character string that uniquely identifies this resource. Can also be the unique_name of the Conversation.

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

_16
// Download the helper library from https://www.twilio.com/docs/node/install
_16
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_16
_16
// Find your Account SID and Auth Token at twilio.com/console
_16
// and set the environment variables. See http://twil.io/secure
_16
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_16
const authToken = process.env.TWILIO_AUTH_TOKEN;
_16
const client = twilio(accountSid, authToken);
_16
_16
async function deleteConversation() {
_16
await client.conversations.v1
_16
.conversations("CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_16
.remove();
_16
}
_16
_16
deleteConversation();


Rate this page: