---
source_url: https://www.pubnub.com/docs/sdks/javascript/api-reference/objects
title: App Context API for JavaScript SDK
updated_at: 2026-06-04T11:11:56.849Z
sdk_name: PubNub JavaScript SDK
sdk_version: 11.0.1
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# App Context API for JavaScript SDK

PubNub JavaScript SDK, use the latest version: 11.0.1

Install:

```bash
npm install pubnub@11.0.1
```

This page describes App Context (formerly Objects v2). To upgrade from Objects v1, refer to the [migration guide](https://www.pubnub.com/docs/general/resources/migration-guides/objects-v2-migration).

App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to store metadata about your application users and channels, and their membership associations, without running your own databases.

PubNub also triggers events when object data changes: set, update, or removal. Setting the same data again doesn't trigger an event. Clients can receive these events in real time and update their front-end application accordingly.

:::note Supported and recommended asynchronous patterns
PubNub supports [Callbacks, Promises, and Async/Await](https://javascript.info/async) for asynchronous JS operations. The recommended pattern is Async/Await and all sample requests in this document are based on it. This pattern returns a status only on detecting an error. To receive the error status, you must add the [try...catch](https://javascript.info/try-catch) syntax to your code.
:::

## User

### Get metadata for all users

Returns a paginated list of UUID metadata. Optionally includes Custom.

:::warning Required keyset configuration
To get all channel and user metadata, you must uncheck the
Disallow Get All Channel Metadata
and
Disallow Get All User Metadata
checkboxes in the App Context section of your keyset configuration in the
[Admin Portal](https://admin.pubnub.com)
.
:::

#### Method(s)

To `Get All UUID Metadata`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.getAllUUIDMetadata({
    include: any,
    filter: string,
    sort: any,
    limit: number,
    page: any
})
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| include | any | Optional |  | Whether to include additional fields. |
| > totalCount | Boolean | Optional | `false` | Whether to include the total count in the paginated response. Default is false. |
| > customFields | Boolean | Optional | `false` | Whether to include the Custom object in the response. |
| filter | string | Optional |  | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| sort | any | Optional |  | Sort by id, name, updated with asc/desc for sort direction (for example, `{name: 'asc'}`). |
| limit | number | Optional | `100` | Number of objects to return. Default/Max: 100. |
| page | any | Optional |  | Cursor-based pagination. |
| > next | String | Optional |  | Cursor-based pagination. |
| > prev | String | Optional |  | Cursor-based pagination. Ignored if the `next` parameter is supplied. |

#### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```javascript
import PubNub from 'pubnub';
// Initialize PubNub with your keys
const pubnub = new PubNub({
  publishKey: 'YOUR_PUBLISH_KEY',
  subscribeKey: 'YOUR_SUBSCRIBE_KEY',
  userId: 'YOUR_USER_ID',
});
```

```javascript
// Function to get all UUID metadata
// to get some data in response, add user metadata using setUUIDMetadata method
async function getAllUUIDMetadata() {
  try {
    const response = await pubnub.objects.getAllUUIDMetadata();
    console.log('getAllUUIDMetadata response:', response);
  } catch (error) {
    console.error(
      `Get all UUID metadata error: ${error}.${
        (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
      }`,
    );
  }
}

// Execute the function to get UUID metadata
getAllUUIDMetadata();
```

#### Response

```json
{
    "status": 200,
    "data": [
        {
            "id": "uuid-1",
            "name": "John Doe",
            "externalId": null,
            "profileUrl": null,
            "email": "johndoe@pubnub.com",
            "custom": null,
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
        },
        {
            "id": "uuid-2",
            "name": "Bob Cat",
            "externalId": null,
            "profileUrl": null,
            "email": "bobc@example.com",
            "custom": {
                "phone": "999-999-9999"
            },
            "updated": "2019-02-21T03:29:00.173452",
            "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
        }
    ]
}
```

### Get user metadata

Returns metadata for the specified UUID, optionally including the custom data object for each.

#### Method(s)

To `Get UUID Metadata`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.getUUIDMetadata({
    uuid: string,
    include: any
})
```

| Parameter | Description |
| --- | --- |
| `uuid`Type: stringDefault: current `uuid` | UUID. If not supplied, the current user's UUID is used. |
| `include`Type: anyDefault: n/a | Whether to include additional fields. |
| `> customFields`Type: BooleanDefault: `true` | Whether to include the Custom object in the response. |

#### Sample code

```javascript
// Using UUID from the config  - default when uuid is not passed in the method
try {
  const response = await pubnub.objects.getUUIDMetadata();
  console.log('getUUIDMetadata response:', response);
} catch (error) {
  console.error(
    `Get UUID metadata error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}

// Using the passed in UUID
try {
  const response = await pubnub.objects.getUUIDMetadata({
    uuid: 'myUuid',
  });
  console.log('getUUIDMetadata response:', response);
} catch (error) {
  console.error(
    `Get UUID metadata error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
    "status": 200,
    "data": {
        "id": "uuid-1",
        "name": "John Doe",
        "externalId": null,
        "profileUrl": null,
        "email": "johndoe@pubnub.com",
        "updated": "2019-02-20T23:11:20.893755",
        "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
    }
}
```

### Set user metadata

:::warning Unsupported partial updates of custom metadata
The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:
1. Get the existing metadata and store it locally.
2. Append the new custom metadata to the existing one.
3. Set the entire updated custom object.
:::

Set metadata for a UUID in the database, optionally including the custom data object for each.

#### Method(s)

To `Set UUID Metadata`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.setUUIDMetadata({
    uuid: string,
    data: any,
    include: any,
    ifMatchesEtag: string
})
```

| Parameter | Description |
| --- | --- |
| `uuid`Type: stringDefault: current `uuid` | Unique user identifier. If not supplied then current user's `uuid` is used. |
| `data` *Type: anyDefault: n/a | JSON object with UUID metadata to set. |
| `> name`Type: stringDefault: n/a | Display name for the user. |
| `> externalId`Type: stringDefault: n/a | User's identifier in an external system |
| `> profileUrl`Type: stringDefault: n/a | The URL of the user's profile picture |
| `> email`Type: stringDefault: n/a | The user's email address. |
| `> custom`Type: anyDefault: n/a | Custom JSON values. Can be strings, numbers, or booleans. Filtering by Custom isn’t supported. |
| `include`Type: anyDefault: n/a | Whether to include additional fields. |
| `> customFields`Type: booleanDefault: `true` | Whether to include the Custom object in the response. |
| `ifMatchesEtag`Type: stringDefault: n/a | Use the eTag from an applicable get metadata call to ensure updates only apply if the object hasn’t changed. If the eTags differ, the server returns HTTP 412. |

:::tip API limits
To learn about the maximum length of parameters used to set user metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-user-metadata).
:::

#### Sample code

```javascript
// Using UUID from the config  - default when uuid is not passed in the method
try {
  const response = await pubnub.objects.setUUIDMetadata({
    data: {
      name: 'John Doe',
    },
  });
  console.log('setUUIDMetadata response:', response);
} catch (error) {
  console.error(
    `Set UUID metadata error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}

// Using the passed in UUID
try {
  const response = await pubnub.objects.setUUIDMetadata({
    uuid: 'myUuid',
    data: {
      email: 'john.doe@example.com',
    },
  });
  console.log('setUUIDMetadata response:', response);
} catch (error) {
  console.error(
    `Set UUID metadata error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
    "status": 200,
    "data": {
        "id": "uuid-1",
        "name": "John Doe",
        "externalId": null,
        "profileUrl": null,
        "email": "johndoe@pubnub.com",
        "updated": "2019-02-20T23:11:20.893755",
        "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
    }
}
```

### Remove user metadata

Removes the metadata from a specified UUID.

#### Method(s)

To `Remove UUID Metadata`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.removeUUIDMetadata({
    uuid: string
})
```

| Parameter | Description |
| --- | --- |
| `uuid`Type: stringDefault: current `uuid` | Unique user identifier. If not supplied then current user's `uuid` is used. |

#### Sample code

```javascript
// Using UUID from the config  - default when uuid is not passed in the method
try {
  const response = await pubnub.objects.removeUUIDMetadata();
} catch (error) {
  console.error(
    `Remove UUID metadata error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}

// Using the passed in UUID
try {
  const response = await pubnub.objects.removeUUIDMetadata({
    uuid: 'myUuid',
  });
} catch (error) {
  console.error(
    `Remove UUID metadata error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
    "status": 0,
    "data": {}
}
```

## Channel

### Get metadata for all channels

Returns a paginated list of channel metadata. Optionally includes Custom.

:::warning Required keyset configuration
To get all channel and user metadata, you must uncheck the
Disallow Get All Channel Metadata
and
Disallow Get All User Metadata
checkboxes in the App Context section of your keyset configuration in the
[Admin Portal](https://admin.pubnub.com)
.
:::

#### Method(s)

To `Get All Channel Metadata`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.getAllChannelMetadata({
    include: any,
    filter: string,
    sort: any,
    limit: number,
    page: any
})
```

| Parameter | Description |
| --- | --- |
| `include`Type: anyDefault: n/a | Whether to include additional fields. |
| `> totalCount`Type: BooleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `> customFields`Type: BooleanDefault: `false` | Whether to include the Custom object in the response. |
| `filter`Type: stringDefault: n/a | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: anyDefault: n/a | Sort by id, name, updated with asc/desc for sort direction (for example, `{name: 'asc'}`). |
| `limit`Type: numberDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: anyDefault: n/a | Cursor-based pagination. |
| `> next`Type: stringDefault: n/a | Cursor-based pagination. |
| `> prev`Type: stringDefault: n/a | Cursor-based pagination. Ignored if the `next` parameter is supplied. |

#### Sample code

```javascript
// Get the total number of channels included in the response.
try {
  const response = await pubnub.objects.getAllChannelMetadata({
    include: {
      totalCount: true,
    },
  });
} catch (error) {
  console.error(
    `Get all channel metadata error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}

// Get all channels with the filter option. To get all channel which has Id ending 'Team'.
try {
  const response = await pubnub.objects.getAllChannelMetadata({
    filter: 'name LIKE "*Team"',
  });
  console.log('Get all channel metadata response:', response);
} catch (error) {
  console.error(
    `Get all channel metadata error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
    "status": 200,
    "data": [
        {
            "id": "team.blue",
            "name": "Blue Team",
            "description": "The channel for Blue team and no other teams.",
            "custom": null,
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
        },
        {
            "id": "team.red",
            "name": "Red Team",
            "description": "The channel for Red team and no other teams.",
            "custom": null,
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
        },
        {
            "id": "team.all",
            "name": "All Teams channel",
            "description": "The channel for all teams",
            "custom": {
                "public": true,
                "motd": "Red and Blue makes Purple!"
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
        }
    ],
    "totalCount": 9,
    "next": "MUIwQTAwMUItQkRBRC00NDkyLTgyMEMtODg2OUU1N0REMTNBCg==",
    "prev": "M0FFODRENzMtNjY2Qy00RUExLTk4QzktNkY1Q0I2MUJFNDRCCg=="
}
```

### Get channel metadata

Returns metadata for the specified Channel, optionally including the custom data object for each.

#### Method(s)

To `Get Channel Metadata`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.getChannelMetadata({
    channel: string,
    include: any
})
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: stringDefault: n/a | Channel name. |
| `include`Type: anyDefault: n/a | Whether to include additional fields. |
| `> customFields`Type: BooleanDefault: `true` | Whether to include the Custom object in the response. |

#### Sample code

```javascript
try {
  const response = await pubnub.objects.getChannelMetadata({
    // `channel` is the `id` in the _metadata_, not `name`
    channel: 'team.blue',
  });
  console.log('Get channel metadata response:', response);
} catch (error) {
  console.error(
    `Get channel metadata error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
    "status": 200,
    "data": {
        "id": "team.blue",
        "name": "Blue Team",
        "description": "The channel for Blue team and no other teams.",
        "updated": "2019-02-20T23:11:20.893755",
        "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
    }
}
```

### Set channel metadata

:::warning Unsupported partial updates of custom metadata
The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:
1. Get the existing metadata and store it locally.
2. Append the new custom metadata to the existing one.
3. Set the entire updated custom object.
:::

Set metadata for a Channel in the database, optionally including the custom data object for each.

#### Method(s)

To `Set Channel Metadata`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.setChannelMetadata({
    channel: string,
    data: any,
    include: any,
    ifMatchesEtag: string
})
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: stringDefault: n/a | Channel name. |
| `data` *Type: anyDefault: n/a | JSON object with channel metadata to set. |
| `> name`Type: stringDefault: n/a | Name of a channel. |
| `> description`Type: stringDefault: n/a | Description of a channel. |
| `> custom`Type: anyDefault: n/a | Custom JSON values. Can be strings, numbers, or booleans. Filtering by Custom isn’t supported. |
| `include`Type: anyDefault: n/a | Whether to include additional fields. |
| `> customFields`Type: booleanDefault: `true` | Whether to include the Custom object in the response. |
| `ifMatchesEtag`Type: stringDefault: n/a | Use the eTag from an applicable get metadata call to ensure updates only apply if the object hasn’t changed. If the eTags differ, the server returns HTTP 412. |

:::tip API limits
To learn about the maximum length of parameters used to set channel metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-channel-metadata).
:::

#### Sample code

```javascript
try {
  const response = await pubnub.objects.setChannelMetadata({
    channel: 'team.red',
    data: {
      name: 'Red Team',
      description: 'The channel for Red team and no other teams.',
      custom: {
        owner: 'Red Leader',
      },
    },
    include: {
      customFields: false,
    },
  });
  console.log('Set channel metadata response:', response);
} catch (error) {
  console.error(
    `Set channel metadata error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
    "status": 200,
    "data": {
        "id": "team.red",
        "name": "Red Team",
        "description": "The channel for Blue team and no other teams.",
        "updated": "2019-02-20T23:11:20.893755",
        "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
    }
}
```

#### Other examples

##### Iteratively update existing metadata

```javascript
const channel = 'team.red';
const name = 'Red Team';
const description = 'The channel for Red team.';
const customField = { visible: 'team' };

// Function to set and then update channel metadata
try {
  const response = await pubnub.objects.setChannelMetadata({
    channel: channel,
    data: {
      name: name,
      description: description,
      custom: customField,
    },
  });
  console.log('The channel has been created with name and description.\n');

  // Fetch current object with custom fields
  const currentObjectResponse = await pubnub.objects.getChannelMetadata({
    channel: channel,
    include: {
      customFields: true,
    },
  });
  const currentObject = currentObjectResponse.data;

  // Initialize the custom field object
  const custom = currentObject.custom || {};

  // Add or update the field
  custom['edit'] = 'admin';

  // Writing the updated object back to the server
  const setResponse = await pubnub.objects.setChannelMetadata({
    channel: channel,
    data: {
      name: currentObject.name || '',
      description: currentObject.description || '',
      custom: custom,
    },
  });
  console.log('Object has been updated', setResponse);
} catch (error) {
  console.error(
    `Set channel metadata error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

### Remove channel metadata

Removes the metadata from a specified channel.

#### Method(s)

To `Remove Channel Metadata`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.removeChannelMetadata({
    channel: string
})
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: StringDefault: n/a | Channel name. |

#### Sample code

```javascript
try {
  const response = await pubnub.objects.removeChannelMetadata({
    channel: 'team.red',
  });
} catch (error) {
  console.error(
    `Remove channel metadata error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
    "status": 0,
    "data": {}
}
```

## Channel memberships

### Get channel memberships

Returns a list of channel memberships for a user. Does not include subscriptions.

#### Method(s)

To `Get Memberships`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.getMemberships({
    uuid: string,
    include: any,
    filter: string,
    sort: any,
    limit: number,
    page: any
})
```

| Parameter | Description |
| --- | --- |
| `uuid`Type: stringDefault: current `uuid` | Unique user identifier. If not supplied then current user's `uuid` is used. |
| `include`Type: anyDefault: n/a | Whether to include additional fields. |
| `> totalCount`Type: booleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `> customFields`Type: booleanDefault: `false` | Whether to include `custom` fields in the response. |
| `> channelFields`Type: booleanDefault: `false` | Whether to include fields for channel metadata in the response. |
| `> customChannelFields`Type: booleanDefault: `false` | Whether to include custom fields for channel metadata in the response. |
| `> statusField`Type: booleanDefault: `false` | Whether to include the membership's status field in the response. |
| `> typeField`Type: booleanDefault: `false` | Whether to include the membership's type field in the response. |
| `> channelStatusField`Type: booleanDefault: `false` | Whether to include the nested `channel` object's `status` from channel metadata (`include=channel.status`; distinct from membership `statusField`). |
| `> channelTypeField`Type: booleanDefault: `false` | Whether to include the nested `channel` object's `type` from channel metadata (`include=channel.type`; distinct from membership `typeField`). |
| `filter`Type: stringDefault: n/a | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: anyDefault: n/a | Sort by updated, status, type, channel.id, channel.name, channel.updated, channel.status, channel.type with asc/desc for sort direction (for example, `{channel.name: 'asc'}`). |
| `limit`Type: numberDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: anyDefault: n/a | Cursor-based pagination. |
| `> next`Type: stringDefault: n/a | Cursor-based pagination. |
| `> prev`Type: stringDefault: n/a | Cursor-based pagination. Ignored if the `next` parameter is supplied. |

#### Sample code

```javascript
// Using UUID from the config
try {
  const response = await pubnub.objects.getMemberships();
} catch (error) {
  console.error(
    `Get memberships error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}

// Using the passed in UUID
try {
  const response = await pubnub.objects.getMemberships({
    uuid: 'myUuid',
    include: {
      channelFields: true,
    },
  });
} catch (error) {
  console.error(
    `Get memberships with channels fields included error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}

// Get all memberships that are starred by the user
try {
  const response = await pubnub.objects.getMemberships({
    uuid: 'myUuid',
    filter: 'custom.starred == true',
  });
} catch (error) {
  console.error(
    `Get filtered memberships error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
    "status": 200,
    "data": [
        {
            "channel": {
                "id": "my-channel",
                "name": "My channel",
                "description": "A channel that is mine",
                "custom": null,
                "updated": "2019-02-20T23:11:20.893755",
                "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
            },
            "custom": {
                "starred": false
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RUNDMDUwNjktNUYwRC00RTI0LUI1M0QtNUUzNkE2NkU0MEVFCg=="
        },
        {
            "channel": {
                "id": "main",
                "name": "Main channel",
                "description": "The main channel",
                "custom": {
                    "public": true,
                    "motd": "Always check your spelling!"
                },
                "updated": "2019-02-20T23:11:20.893755",
                "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RUNDMDUwNjktNUYwRC00RTI0LUI1M0QtNUUzNkE2NkU0MEVFCg=="
        }
    ],
    "totalCount": 7,
    "next": "RDIwQUIwM0MtNUM2Ni00ODQ5LUFGRjMtNDk1MzNDQzE3MUVCCg==",
    "prev": "MzY5RjkzQUQtNTM0NS00QjM0LUI0M0MtNjNBQUFGODQ5MTk2Cg=="
}
```

### Set channel memberships

Set channel memberships for a UUID.

#### Method(s)

To `Set Memberships`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.setMemberships({
    uuid: string,
    channels: Array<string>,
    include: any,
    filter: string,
    sort: any,
    limit: number,
    page: any
})
```

| Parameter | Description |
| --- | --- |
| `uuid`Type: stringDefault: current `uuid` | Unique user identifier. If not supplied then current user's `uuid` is used. |
| `channels` *Type: Array`<string>`Default: N/A | Array of `channels` to add to membership. Array can contain strings (channel-name only) or objects which can include custom data, like status or type, for example: `{ id: "my-channel-3", custom: { owner: "PubNubUser" }, type: "regular_membership", status: "active" }`. |
| `include`Type: anyDefault: n/a | Whether to include additional fields. |
| `> totalCount`Type: booleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `> customFields`Type: booleanDefault: `false` | Whether to include `custom` fields in the response. |
| `> statusField`Type: booleanDefault: `false` | Whether to include the membership's status field in the response. |
| `> typeField`Type: booleanDefault: `false` | Whether to include the membership's type field in the response. |
| `> channelFields`Type: booleanDefault: `false` | Whether to include fields for channel metadata in the response. |
| `> customChannelFields`Type: booleanDefault: `false` | Whether to include custom fields for channel metadata in the response. |
| `> channelStatusField`Type: booleanDefault: `false` | Whether to include the nested `channel` object's `status` from channel metadata (`include=channel.status`; distinct from membership `statusField`). |
| `> channelTypeField`Type: booleanDefault: `false` | Whether to include the nested `channel` object's `type` from channel metadata (`include=channel.type`; distinct from membership `typeField`). |
| `filter`Type: StringDefault: N/A | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: anyDefault: n/a | Sort by updated, status, type, channel.id, channel.name, channel.updated, channel.status, channel.type with asc/desc for sort direction (for example, `{channel.name: 'asc'}`). |
| `limit`Type: NumberDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: anyDefault: n/a | Cursor-based pagination. |
| `> next`Type: stringDefault: n/a | Cursor-based pagination. |
| `> prev`Type: stringDefault: n/a | Cursor-based pagination. Ignored if the `next` parameter is supplied. |

:::tip API limits
To learn about the maximum length of parameters used to set channel membership metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-membership-metadata).
:::

#### Sample code

```javascript
// Using UUID from the config
try {
  const response = await pubnub.objects.setMemberships({
    channels: [
      'my-channel',
      { id: 'channel-with-status-type', custom: { hello: 'World' }, status: 'helloStatus', type: 'helloType' },
    ],
  });
  console.log('Set memberships response:', response);
} catch (error) {
  console.error(
    `Set memberships error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}

// Using the passed in UUID
try {
  const response = await pubnub.objects.setMemberships({
    uuid: 'my-uuid',
    channels: [
      'my-channel',
      { id: 'channel-with-status-type', custom: { hello: 'World' }, status: 'helloStatus', type: 'helloType' },
    ],
    include: {
      // To include channel fields in response
      channelFields: true,
    },
  });
  console.log('Set memberships response:', response);
} catch (error) {
  console.error(
    `Set memberships error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
    "status": 200,
    "data": [
        {
            "channel": {
              "id": "my-channel",
              "name": "My channel",
              "description": "A channel that is mine",
              "custom": null,
              "updated": "2019-02-20T23:11:20.893755",
              "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
            },
            "custom": {
                "starred": false
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RUNDMDUwNjktNUYwRC00RTI0LUI1M0QtNUUzNkE2NkU0MEVFCg=="
        },
        {
          "channel": {
              "id": "main",
              "name": "Main channel",
              "description": "The main channel",
              "custom": {
                  "public": true,
                  "motd": "Always check your spelling!"
              },
              "updated": "2019-02-20T23:11:20.893755",
              "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
          },
          "updated": "2019-02-20T23:11:20.893755",
          "eTag": "RUNDMDUwNjktNUYwRC00RTI0LUI1M0QtNUUzNkE2NkU0MEVFCg=="
        }
    ],
    "totalCount": 7,
    "next": "RDIwQUIwM0MtNUM2Ni00ODQ5LUFGRjMtNDk1MzNDQzE3MUVCCg==",
    "prev": "MzY5RjkzQUQtNTM0NS00QjM0LUI0M0MtNjNBQUFGODQ5MTk2Cg=="
}
```

### Remove channel memberships

Remove channel memberships for a UUID.

#### Method(s)

To `Remove Memberships`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.removeMemberships({
    uuid: string,
    channels: Array<string>,
    include: any,
    filter: string,
    sort: any,
    limit: number,
    page: any
})
```

| Parameter | Description |
| --- | --- |
| `uuid`Type: stringDefault: current `uuid` | Unique user identifier. If not supplied then current user's `uuid` is used. |
| `channels` *Type: Array`<string>`Default: N/A | Channels to remove from membership. |
| `include`Type: anyDefault: n/a | Whether to include additional fields. |
| `> totalCount`Type: booleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `> customFields`Type: booleanDefault: `false` | Whether to include the Custom object in the response. |
| `> channelFields`Type: booleanDefault: `false` | Include fields for channels metadata. |
| `> customChannelFields`Type: booleanDefault: `false` | Include custom fields for channels metadata. |
| `filter`Type: stringDefault: N/A | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: anyDefault: n/a | Sort by updated, channel.id, channel.name, channel.updated with asc/desc for sort direction (for example, `{channel.name: 'asc'}`). |
| `limit`Type: NumberDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: anyDefault: n/a | Cursor-based pagination. |
| `> next`Type: stringDefault: n/a | Cursor-based pagination. |
| `> prev`Type: stringDefault: n/a | Cursor-based pagination. Ignored if the `next` parameter is supplied. |

#### Sample code

```javascript
// Using UUID from the config
try {
  const response = await pubnub.objects.removeMemberships({
    channels: ['ch-1', 'ch-2'],
  });
} catch (error) {
  console.error(
    `Remove memberships error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}

// Using the passed in UUID
try {
  const response = await pubnub.objects.removeMemberships({
    uuid: 'myUuid',
    channels: ['ch-1', 'ch-2'],
  });
} catch (error) {
  console.error(
    `Remove memberships for given uuids error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
    "status": 200,
    "data": [
        {
            "channel": {
              "id": "my-channel",
              "name": "My channel",
              "description": "A channel that is mine",
              "custom": null,
              "updated": "2019-02-20T23:11:20.893755",
              "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
            },
            "custom": {
                "starred": false
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RUNDMDUwNjktNUYwRC00RTI0LUI1M0QtNUUzNkE2NkU0MEVFCg=="
        },
        {
            "channel": {
              "id": "main",
              "name": "Main channel",
              "description": "The main channel",
              "custom": {
                  "public": true,
                  "motd": "Always check your spelling!"
              },
              "updated": "2019-02-20T23:11:20.893755",
              "eTag": "RTc1NUQwNUItREMyNy00Q0YxLUJCNDItMEZDMTZDMzVCN0VGCg=="
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "RUNDMDUwNjktNUYwRC00RTI0LUI1M0QtNUUzNkE2NkU0MEVFCg=="
        }
    ],
    "totalCount": 7,
    "next": "RDIwQUIwM0MtNUM2Ni00ODQ5LUFGRjMtNDk1MzNDQzE3MUVCCg==",
    "prev": "MzY5RjkzQUQtNTM0NS00QjM0LUI0M0MtNjNBQUFGODQ5MTk2Cg=="
}
```

## Channel members

### Get channel members

Returns a list of channel members. Includes user metadata when available.

#### Method(s)

To `Get Channel Members`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.getChannelMembers({
    channel: string,
    include: any,
    filter: string,
    sort: any,
    limit: number,
    page: any
})
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: stringDefault: n/a | Channel name. |
| `include`Type: anyDefault: n/a | Whether to include additional fields. |
| `> totalCount`Type: booleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `> customFields`Type: booleanDefault: `false` | Whether to include the Custom object in the response. |
| `> UUIDFields`Type: booleanDefault: `false` | Whether to include fields for UUIDs metadata. |
| `> customUUIDFields`Type: booleanDefault: `false` | Whether to include custom fields for UUIDs metadata. |
| `> statusField`Type: booleanDefault: `false` | Whether to include the member's status field in the response. |
| `> typeField`Type: booleanDefault: `false` | Whether to include the member's type field in the response. |
| `> UUIDStatusField`Type: booleanDefault: `false` | Whether to include the nested `uuid` object's `status` from UUID metadata (`include=uuid.status`; distinct from membership `statusField`). |
| `> UUIDTypeField`Type: booleanDefault: `false` | Whether to include the nested `uuid` object's `type` from UUID metadata (`include=uuid.type`; distinct from membership `typeField`). |
| `filter`Type: StringDefault: N/A | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: anyDefault: n/a | Sort by updated, status, type, uuid.id, uuid.name, uuid.updated, uuid.status, uuid.type with asc/desc for sort direction (for example, `{uuid.name: 'asc'}`). |
| `limit`Type: numberDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: anyDefault: n/a | Cursor-based pagination. |
| `> next`Type: stringDefault: n/a | Cursor-based pagination. |
| `> prev`Type: stringDefault: n/a | Cursor-based pagination. Ignored if the `next` parameter is supplied. |

#### Sample code

```javascript
try {
  const response = await pubnub.objects.getChannelMembers({
    channel: 'myChannel',
    include: {
      UUIDFields: true,
    },
  });
  console.log('getChannelMembers response:', response);
} catch (error) {
  console.error(
    `Get channel members error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}

// Get all channel members with "admin" in the description
try {
  const response = await pubnub.objects.getChannelMembers({
    channel: 'myChannel',
    filter: 'description LIKE "*admin*"',
  });
  console.log('getChannelMembers response:', response);
} catch (error) {
  console.error(
    `Get channel members error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
  "status": 200,
  "data": [
    {
      "uuid": {
        "id": "uuid-1",
        "name": "John Doe",
        "externalId": null,
        "profileUrl": null,
        "email": "jack@twitter.com",
        "custom": null,
        "updated": "2019-02-20T23:11:20.893755",
        "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
      },
      "custom": {
        "role": "admin"
      },
      "updated": "2019-02-20T23:11:20.893755",
      "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
    },
    {
      "uuid": {
        "id": "uuid-2",
        "name": "Bob Cat",
        "externalId": null,
        "profileUrl": null,
        "email": "bobc@example.com",
        "custom": {
          "phone": "999-999-9999"
        },
        "updated": "2019-02-21T03:29:00.173452",
        "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
      },
      "updated": "2019-02-20T23:11:20.893755",
      "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
    }
  ],
  "totalCount": 37,
  "next": "RDIwQUIwM0MtNUM2Ni00ODQ5LUFGRjMtNDk1MzNDQzE3MUVCCg==",
  "prev": "MzY5RjkzQUQtNTM0NS00QjM0LUI0M0MtNjNBQUFGODQ5MTk2Cg=="
}
```

### Set channel members

This method sets members in a channel.

#### Method(s)

To `Set Channel Members`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.setChannelMembers({
    channel: string,
    uuids: Array<string>,
    include: any,
    filter: string,
    sort: any,
    limit: number,
    page: any
})
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: stringDefault: n/a | Channel name. |
| `uuids` *Type: ArrayDefault: n/a | Array of members to add to the `channel`. Array can contain strings (uuid only) or objects which can include custom data, for example: `{ id: "uuid-3", custom: { role: "Super Admin" } }`. |
| `include`Type: anyDefault: n/a | Whether to include additional fields. |
| `> totalCount`Type: booleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `> customFields`Type: booleanDefault: `false` | Whether to include the Custom object in the response. |
| `> statusField`Type: booleanDefault: `false` | Whether to include the member's status field in the response. |
| `> typeField`Type: booleanDefault: `false` | Whether to include the member's type field in the response. |
| `> UUIDFields`Type: booleanDefault: `false` | Whether to include fields for UUID's metadata. |
| `> customUUIDFields`Type: booleanDefault: `false` | Whether to include custom fields for UUIDs metadata. |
| `> UUIDStatusField`Type: booleanDefault: `false` | Whether to include the nested `uuid` object's `status` from UUID metadata (`include=uuid.status`; distinct from membership `statusField`). |
| `> UUIDTypeField`Type: booleanDefault: `false` | Whether to include the nested `uuid` object's `type` from UUID metadata (`include=uuid.type`; distinct from membership `typeField`). |
| `filter`Type: stringDefault: N/A | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: anyDefault: n/a | Sort by updated, status, type, uuid.id, uuid.name, uuid.updated, uuid.status, uuid.type with asc/desc for sort direction (for example, `{uuid.name: 'asc'}`). |
| `limit`Type: numberDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: anyDefault: n/a | Cursor-based pagination. |
| `> next`Type: stringDefault: n/a | Cursor-based pagination. |
| `> prev`Type: stringDefault: n/a | Cursor-based pagination. Ignored if the `next` parameter is supplied. |

:::tip API limits
To learn about the maximum length of parameters used to set channel members metadata, refer to [REST API docs](https://www.pubnub.com/docs/sdks/rest-api/set-channel-members-metadata).
:::

#### Sample code

```javascript
try {
  const response = await pubnub.objects.setChannelMembers({
    channel: 'myChannel',
    uuids: ['uuid-1', 'uuid-2', { id: 'uuid-3', custom: { role: 'Super Admin' } }],
  });
  console.log('setChannelMembers response:', response);
} catch (error) {
  console.error(
    `Set channel members error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
    "status": 200,
    "data": [
        {
            "uuid": {
                "id": "uuid-1",
                "name": "John Doe",
                "externalId": null,
                "profileUrl": null,
                "email": "johndoe@pubnub.com",
                "custom": null,
                "updated": "2019-02-20T23:11:20.893755",
                "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
            },
            "custom": {
                "role": "admin"
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
        },
        {
            "uuid": {
                "id": "uuid-2",
                "name": "Bob Cat",
                "externalId": null,
                "profileUrl": null,
                "email": "bobc@example.com",
                "custom": {
                    "phone": "999-999-9999"
                },
                "updated": "2019-02-21T03:29:00.173452",
                "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
        }
    ],
    "totalCount": 37,
    "next": "RDIwQUIwM0MtNUM2Ni00ODQ5LUFGRjMtNDk1MzNDQzE3MUVCCg==",
    "prev": "MzY5RjkzQUQtNTM0NS00QjM0LUI0M0MtNjNBQUFGODQ5MTk2Cg=="
}
```

### Remove channel members

Remove members from a Channel. The `include` object accepts the same fields as [Set channel members](#set-channel-members).

#### Method(s)

To `Remove Channel Members`, you can use the following method(s) in the JavaScript SDK:

```javascript
pubnub.objects.removeChannelMembers({
    channel: string,
    uuids: Array<string>,
    include: any,
    filter: string,
    sort: any,
    limit: number,
    page: any
})
```

| Parameter | Description |
| --- | --- |
| `channel` *Type: stringDefault: N/A | Channel name. |
| `uuids` *Type: String[]Default: N/A | Members to remove from channel. |
| `include`Type: anyDefault: n/a | Whether to include additional fields. |
| `> totalCount`Type: booleanDefault: `false` | Whether to include the total count in the paginated response. Default is false. |
| `> customFields`Type: booleanDefault: `false` | Whether to include the Custom object in the response. |
| `> statusField`Type: booleanDefault: `false` | Whether to include the member's status field in the response. |
| `> typeField`Type: booleanDefault: `false` | Whether to include the member's type field in the response. |
| `> UUIDFields`Type: booleanDefault: `false` | Whether to include fields for UUID's metadata. |
| `> customUUIDFields`Type: booleanDefault: `false` | Whether to include custom fields for UUIDs metadata. |
| `> UUIDStatusField`Type: booleanDefault: `false` | Whether to include the nested `uuid` object's `status` from UUID metadata (`include=uuid.status`; distinct from membership `statusField`). |
| `> UUIDTypeField`Type: booleanDefault: `false` | Whether to include the nested `uuid` object's `type` from UUID metadata (`include=uuid.type`; distinct from membership `typeField`). |
| `filter`Type: stringDefault: N/A | Filter expression. Only matching objects are returned. See [filtering](https://www.pubnub.com/docs/general/metadata/filtering). |
| `sort`Type: anyDefault: n/a | Sort by updated, status, type, uuid.id, uuid.name, uuid.updated, uuid.status, uuid.type with asc/desc for sort direction (for example, `{uuid.name: 'asc'}`). |
| `limit`Type: numberDefault: `100` | Number of objects to return. Default/Max: 100. |
| `page`Type: anyDefault: n/a | Cursor-based pagination. |
| `> next`Type: stringDefault: n/a | Cursor-based pagination. |
| `> prev`Type: stringDefault: n/a | Cursor-based pagination. Ignored if the `next` parameter is supplied. |

#### Sample code

```javascript
try {
  const response = await pubnub.objects.removeChannelMembers({
    channel: 'myChannel',
    uuids: ['uuid-1', 'uuid-2'],
  });
} catch (error) {
  console.error(
    `Remove channel members error: ${error}.${
      (error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
    }`,
  );
}
```

#### Response

```json
{
    "status": 200,
    "data": [
        {
            "uuid": {
                "id": "uuid-1",
                "name": "John Doe",
                "externalId": null,
                "profileUrl": null,
                "email": "johndoe@pubnub.com",
                "custom": null,
                "updated": "2019-02-20T23:11:20.893755",
                "eTag": "MDcyQ0REOTUtNEVBOC00QkY2LTgwOUUtNDkwQzI4MjgzMTcwCg=="
            },
            "custom": {
                "role": "admin"
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
        },
        {
            "uuid": {
                "id": "uuid-2",
                "name": "Bob Cat",
                "externalId": null,
                "profileUrl": null,
                "email": "bobc@example.com",
                "custom": {
                    "phone": "999-999-9999"
                },
                "updated": "2019-02-21T03:29:00.173452",
                "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
            },
            "updated": "2019-02-20T23:11:20.893755",
            "eTag": "QkRENDA5MjItMUZCNC00REI5LUE4QTktRjJGNUMxNTc2MzE3Cg=="
        }
    ],
    "totalCount": 37,
    "next": "RDIwQUIwM0MtNUM2Ni00ODQ5LUFGRjMtNDk1MzNDQzE3MUVCCg==",
    "prev": "MzY5RjkzQUQtNTM0NS00QjM0LUI0M0MtNjNBQUFGODQ5MTk2Cg=="
}
```

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **Channel pattern** - A way to group and analyze channel data to track performance metrics like message counts and user engagement over time with PubNub Insights.
* **User** - An individual or entity that interacts with a system, application, or service. In PubNub, a user typically refers to someone who sends or receives messages through the platform, identified by a unique user ID or username.
* **User ID** - UTF-8 encoded, unique string of up to 92 characters used to identify a single client (end user, device, or server) that connects to PubNub.