Skip to contentSkip to navigationSkip to topbar
On this page

Users Resource


(error)

Danger

Programmable Chat has been deprecated and is no longer supported. Instead, we'll be focusing on the next generation of chat: Twilio Conversations. Find out more about the EOL process here(link takes you to an external page).

If you're starting a new project, please visit the Conversations Docs to begin. If you've already built on Programmable Chat, please visit our Migration Guide to learn about how to switch.

(error)

Danger

This is reference documentation for the v1 REST API, which has been deprecated. You should use the current v2 REST API.

The User resource of Programmable Chat represents a particular user represented by an Identity as provided by the developer. Users exist within a single Chat Service instance. Users need to be unique (by Identity) within a Service instance.

User records are used to assign permissions via Roles within a Service instance and determine what the user can and cannot do within the instance.

Users can be created within a Service instance via the client capability token or via the User resource REST API methods.

The first time a new Identity is encountered by Chat within a Service instance, a new User instance will be created using the Identity encountered.
If the Identity exists, the existing User record will be used for that session/request. This is true for endpoints and Access Tokens, and for creating Members in a POST to the Members resource.

Users can also be retrieved by either User Sid or Identity via a GET to the Users resource.


Properties

properties page anchor

Each user has these properties:

Property nameTypeRequiredDescriptionChild properties
sidSID<US>

Optional

Not PII

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

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

account_sidSID<AC>

Optional

The SID of the Account that created the User resource.

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

service_sidSID<IS>

Optional

The SID of the Service the resource is associated with.

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

attributesstring

Optional

PII MTL: 30 days

The JSON string that stores application-specific data. Note If this property has been assigned a value, it's only displayed in a FETCH action that returns a single resource; otherwise, it's null. If the attributes have not been set, {} is returned.


friendly_namestring

Optional

The string that you assigned to describe the resource.


role_sidSID<RL>

Optional

The SID of the Role assigned to the user.

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

identitystring

Optional

The application-defined string that uniquely identifies the resource's User within the Service. This value is often a username or an email address. See access tokens for more info.


is_onlineboolean

Optional

Whether the User is actively connected to the Service instance and online. This value is only returned by Fetch actions that return a single resource and null is always returned by a Read action. This value is null if the Service's reachability_enabled is false, if the User has never been online for the Service instance, even if the Service's reachability_enabled is true.


is_notifiableboolean

Optional

Whether the User has a potentially valid Push Notification registration (APN or GCM) for the Service instance. If at least one registration exists, true; otherwise false. This value is only returned by Fetch actions that return a single resource and null is always returned by a Read action. This value is null if the Service's reachability_enabled is false, and if the User has never had a notification registration, even if the Service's reachability_enabled is true.


date_createdstring<date-time>

Optional

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


date_updatedstring<date-time>

Optional

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


joined_channels_countinteger

Optional

The number of Channels this User is a Member of.

Default: 0

linksobject<uri-map>

Optional

The absolute URLs of the Channel and Binding resources related to the user.


urlstring<uri>

Optional

The absolute URL of the User resource.


1
GET /Services/{Instance SID}/Users
2
List all UsersLink to code sample: List all Users
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 listUser() {
11
const users = await client.chat.v1
12
.services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.users.list({ limit: 20 });
14
15
users.forEach((u) => console.log(u.sid));
16
}
17
18
listUser();

Output

1
{
2
"meta": {
3
"page": 0,
4
"page_size": 50,
5
"first_page_url": "https://chat.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users?PageSize=50&Page=0",
6
"previous_page_url": null,
7
"url": "https://chat.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users?PageSize=50&Page=0",
8
"next_page_url": null,
9
"key": "users"
10
},
11
"users": [
12
{
13
"sid": "USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
14
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
15
"service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
16
"role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
17
"identity": "jing",
18
"attributes": null,
19
"is_online": true,
20
"is_notifiable": null,
21
"friendly_name": null,
22
"date_created": "2016-03-24T21:05:19Z",
23
"date_updated": "2016-03-24T21:05:19Z",
24
"joined_channels_count": 0,
25
"links": {
26
"user_channels": "https://chat.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels"
27
},
28
"url": "https://chat.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
29
}
30
]
31
}

1
POST /Services/{Instance SID}/Users
2

Parameters

parameters page anchor
Property nameTypeRequiredPIIDescription
ServiceSidSID<IS>required

The SID of the Service to create the resource under.

Pattern: ^IS[0-9a-fA-F]{32}$Min length: 34Max length: 34
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
Identitystringrequired

The identity value that uniquely identifies the new resource's User within the Service. This value is often a username or email address. See the Identity documentation for more details.


RoleSidSID<RL>

Optional

The SID of the Role assigned to the new User.

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

Attributesstring

Optional

A valid JSON string that contains application-specific data.


FriendlyNamestring

Optional

A descriptive string that you create to describe the new resource. This value is often used for display purposes.

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 createUser() {
11
const user = await client.chat.v1
12
.services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.users.create({ identity: "IDENTITY" });
14
15
console.log(user.sid);
16
}
17
18
createUser();

Output

1
{
2
"sid": "USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"service_sid": "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
5
"role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"identity": "IDENTITY",
7
"attributes": null,
8
"is_online": true,
9
"is_notifiable": null,
10
"friendly_name": null,
11
"joined_channels_count": 0,
12
"date_created": "2016-03-24T21:05:19Z",
13
"date_updated": "2016-03-24T21:05:19Z",
14
"links": {
15
"user_channels": "https://chat.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels"
16
},
17
"url": "https://chat.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
18
}

1
GET /Services/{Instance SID}/Users/{Identity}
2
1
GET /Services/{Instance SID}/Users/{User SID}
2
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 fetchUser() {
11
const user = await client.chat.v1
12
.services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.users("USXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
14
.fetch();
15
16
console.log(user.sid);
17
}
18
19
fetchUser();

Output

1
{
2
"sid": "USXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"service_sid": "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
5
"role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"identity": "jing",
7
"attributes": null,
8
"is_online": true,
9
"is_notifiable": null,
10
"friendly_name": null,
11
"joined_channels_count": 0,
12
"date_created": "2016-03-24T21:05:19Z",
13
"date_updated": "2016-03-24T21:05:19Z",
14
"links": {
15
"user_channels": "https://chat.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels"
16
},
17
"url": "https://chat.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
18
}

1
POST /Services/{Instance SID}/Users/{User SID}
2
Property nameTypeRequiredPIIDescription
ServiceSidSID<IS>required

The SID of the Service to update the resource from.

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

Sidstringrequired

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

Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
RoleSidSID<RL>

Optional

The SID of the Role assigned to this user.

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

Attributesstring

Optional

A valid JSON string that contains application-specific data.


FriendlyNamestring

Optional

A descriptive string that you create to describe the resource. It is often used for display purposes.

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 updateUser() {
11
const user = await client.chat.v1
12
.services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.users("USXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
14
.update({ roleSid: "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" });
15
16
console.log(user.sid);
17
}
18
19
updateUser();

Output

1
{
2
"sid": "USXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"service_sid": "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
5
"role_sid": "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
6
"identity": "jing",
7
"attributes": null,
8
"is_online": true,
9
"is_notifiable": null,
10
"friendly_name": null,
11
"joined_channels_count": 0,
12
"date_created": "2016-03-24T21:05:19Z",
13
"date_updated": "2016-03-24T21:05:19Z",
14
"links": {
15
"user_channels": "https://chat.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels"
16
},
17
"url": "https://chat.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users/USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
18
}

1
DELETE /Services/{Instance SID}/Users/{User SID}
2
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 deleteUser() {
11
await client.chat.v1
12
.services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.users("USXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
14
.remove();
15
}
16
17
deleteUser();

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.