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

Role Resource


In Twilio Conversations, the Role Resource represents what a User can do within the Service and individual Conversations. Roles are scoped to either a Service or a Conversation.

Users are assigned a Role at the Service level. This determines what they can do within the chat Service instance, such as create and destroy Conversations within the Service.

Participants are assigned a Role at the Conversation level. This determines what they are able to do within a particular Conversation, such as invite Participants to be members of the Conversation, post Messages, and remove other Participants from the Conversation.

See Permission Values for information about the permissions that can be assigned in each scope.

(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 Role 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/Roles/

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/<Service SID, ISXXX...>/Roles/


Each Role resource contains these properties.

Property nameTypePIIDescription
sidSID<RL>
Not PII

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

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

account_sidSID<AC>

The SID of the Account that created the Role resource.

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

chat_service_sidSID<IS>

The SID of the Conversation Service the Role resource is associated with.

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

friendly_namestring
PII MTL: 30 days

The string that you assigned to describe the resource.


typeenum<string>

The type of role. Can be: conversation for Conversation roles or service for Conversation Service roles.

Possible values:
conversationservice

permissionsarray[string]

An array of the permissions the role has been granted.


date_createdstring<date-time>

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


date_updatedstring<date-time>

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


urlstring<uri>

An absolute API resource URL for this user role.


POST https://conversations.twilio.com/v1/Roles

Property nameTypeRequiredPIIDescription
FriendlyNamestringrequired

A descriptive string that you create to describe the new resource. It can be up to 64 characters long.


Typeenum<string>required

The type of role. Can be: conversation for Conversation roles or service for Conversation Service roles.

Possible values:
conversationservice

Permissionarray[string]required

A permission that you grant to the new role. Only one permission can be granted per parameter. To assign more than one permission, repeat this parameter for each permission value. The values for this parameter depend on the role's type.

Create a Role

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

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

Output

_16
{
_16
"sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"friendly_name": "FriendlyName",
_16
"type": "conversation",
_16
"permissions": [
_16
"sendMessage",
_16
"leaveConversation",
_16
"editOwnMessage",
_16
"deleteOwnMessage"
_16
],
_16
"date_created": "2016-03-03T19:47:15Z",
_16
"date_updated": "2016-03-03T19:47:15Z",
_16
"url": "https://conversations.twilio.com/v1/Roles/RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_16
}


GET https://conversations.twilio.com/v1/Roles/{Sid}

Property nameTypeRequiredPIIDescription
SidSID<RL>required

The SID of the Role resource to fetch.

Pattern: ^RL[0-9a-fA-F]{32}$Min length: 34Max length: 34
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 fetchRole() {
_18
const role = await client.conversations.v1
_18
.roles("RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_18
.fetch();
_18
_18
console.log(role.sid);
_18
}
_18
_18
fetchRole();

Output

_16
{
_16
"sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"friendly_name": "Conversation Role",
_16
"type": "conversation",
_16
"permissions": [
_16
"sendMessage",
_16
"leaveConversation",
_16
"editOwnMessage",
_16
"deleteOwnMessage"
_16
],
_16
"date_created": "2016-03-03T19:47:15Z",
_16
"date_updated": "2016-03-03T19:47:15Z",
_16
"url": "https://conversations.twilio.com/v1/Roles/RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_16
}


Read multiple Role resources

read-multiple-role-resources page anchor
GET https://conversations.twilio.com/v1/Roles

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.

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 listRole() {
_16
const roles = await client.conversations.v1.roles.list({ limit: 20 });
_16
_16
roles.forEach((r) => console.log(r.sid));
_16
}
_16
_16
listRole();

Output

_29
{
_29
"meta": {
_29
"page": 0,
_29
"page_size": 50,
_29
"first_page_url": "https://conversations.twilio.com/v1/Roles?PageSize=50&Page=0",
_29
"previous_page_url": null,
_29
"url": "https://conversations.twilio.com/v1/Roles?PageSize=50&Page=0",
_29
"next_page_url": null,
_29
"key": "roles"
_29
},
_29
"roles": [
_29
{
_29
"sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29
"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29
"friendly_name": "Conversation Role",
_29
"type": "conversation",
_29
"permissions": [
_29
"sendMessage",
_29
"leaveConversation",
_29
"editOwnMessage",
_29
"deleteOwnMessage"
_29
],
_29
"date_created": "2016-03-03T19:47:15Z",
_29
"date_updated": "2016-03-03T19:47:15Z",
_29
"url": "https://conversations.twilio.com/v1/Roles/RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_29
}
_29
]
_29
}


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

Property nameTypeRequiredPIIDescription
SidSID<RL>required

The SID of the Role resource to update.

Pattern: ^RL[0-9a-fA-F]{32}$Min length: 34Max length: 34
Property nameTypeRequiredPIIDescription
Permissionarray[string]required

A permission that you grant to the role. Only one permission can be granted per parameter. To assign more than one permission, repeat this parameter for each permission value. Note that the update action replaces all previously assigned permissions with those defined in the update action. To remove a permission, do not include it in the subsequent update action. The values for this parameter depend on the role's type.

Update a Conversation Role

update-a-conversation-role 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 updateRole() {
_18
const role = await client.conversations.v1
_18
.roles("New_Chat_Service_SID")
_18
.update({ permission: ["Permission"] });
_18
_18
console.log(role.sid);
_18
}
_18
_18
updateRole();

Output

_16
{
_16
"sid": "New_Chat_Service_SID",
_16
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"chat_service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_16
"friendly_name": "Conversation Role",
_16
"type": "conversation",
_16
"permissions": [
_16
"sendMessage",
_16
"leaveConversation",
_16
"editOwnMessage",
_16
"deleteOwnMessage"
_16
],
_16
"date_created": "2016-03-03T19:47:15Z",
_16
"date_updated": "2016-03-03T19:47:15Z",
_16
"url": "https://conversations.twilio.com/v1/Roles/RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_16
}


DELETE https://conversations.twilio.com/v1/Roles/{Sid}

Property nameTypeRequiredPIIDescription
SidSID<RL>required

The SID of the Role resource to delete.

Pattern: ^RL[0-9a-fA-F]{32}$Min length: 34Max length: 34
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 deleteRole() {
_16
await client.conversations.v1
_16
.roles("RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_16
.remove();
_16
}
_16
_16
deleteRole();


Service-scope permissions

service-scope-permissions page anchor

These are the available permissions entries for roles where type = service.

PermissionEnables User to:
addParticipantAdd other users as Participants of a Conversation
createConversationCreate new Conversations
deleteAnyMessageDelete any Message in the Service
deleteConversationDelete Conversations
editAnyMessageEdit any Message in the Service
editAnyMessageAttributesEdit any Message attributes in the Service
editAnyUserInfoEdit other User's User Info properties
editConversationAttributesUpdate the optional attributes metadata field on a Conversation
editConversationNameChange the name of a Conversation
editOwnMessageEdit their own Messages in the Service
editOwnMessageAttributesEdit the own Message attributes in the Service
editOwnUserInfoEdit their own User Info properties
joinConversationJoin Conversations
removeParticipantRemove Participants from a Conversation

Conversation-scope permissions

conversation-scope-permissions page anchor

These are the available permissions entries for roles where type = conversation.

PermissionEnables User to:
addParticipantAdd other users as Participants of a Conversation
deleteAnyMessageDelete any Message in the Service
deleteOwnMessageDelete their own Messages in the Service
deleteConversationDelete Conversations
editAnyMessageEdit any Message in the Service
editAnyMessageAttributesEdit any Message attributes in the Service
editAnyUserInfoEdit other User's User Info properties
editConversationAttributesUpdate the optional attributes metadata field on a Conversation
editConversationNameChange the name of a Conversation
editOwnMessageEdit their own Messages in the Service
editOwnMessageAttributesEdit the own Message attributes in the Service
editOwnUserInfoEdit their own User Info properties
leaveConversationLeave a Conversation
removeParticipantRemove Participants from a Conversation
sendMediaMessageSend media Messages to Conversations
sendMessageSend Messages to Conversations

Rate this page: