---
source_url: https://www.pubnub.com/docs/chat/chat-sdk/build/features/users/create
title: Create users
updated_at: 2026-06-12T11:22:34.300Z
---

> 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


# Create users

Use `createUser()` to create a new [User](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/user) with a unique [User ID](https://www.pubnub.com/docs/general/basics/identify-users-and-devices).

:::note Requires App Context
Enable [App Context](https://youtu.be/9UEoSlngpYI) on your keyset in the [Admin Portal](https://admin.pubnub.com/) to store user data.
:::

### Method signature

##### Under the hood

`createUser()` calls App Context API and the JavaScript SDK [setUUIDMetadata()](https://www.pubnub.com/docs/sdks/javascript/api-reference/objects#set-user-metadata) method.

This method takes the following parameters:

```ts
chat.createUser(
    id: string,
    {
        name?: string,
        externalId?: string,
        profileUrl?: string,
        email?: string,
        custom?: ObjectCustom,
        status?: string,
        type?: string
    }
): Promise<User>
```

#### Input

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| id | string | Yes |  | [Unique user identifier](https://www.pubnub.com/docs/general/setup/users-and-devices#user-id-usage). |
| name | string | Optional |  | Display name for the user (must not be empty or consist only of whitespace characters). |
| externalId | string | Optional |  | User's identifier in an external system. You can use it to match `id` with a similar identifier from an external database. |
| profileUrl | string | Optional |  | URL of the user's profile picture. |
| email | string | Optional |  | User's email address. |
| custom | ObjectCustom | Optional |  | JSON providing custom data about the user. Values must be scalar only; arrays or objects are not supported. [Filtering App Context data](https://www.pubnub.com/docs/general/metadata/filtering) through the `custom` property is not recommended in SDKs. |
| status | string | Optional |  | Tag that lets you categorize your app users by their current state. The tag choice is entirely up to you and depends on your use case. For example, you can use `status` to mark users in your chat app as `invited`, `active`, or `archived`. |
| type | string | Optional |  | Tag that lets you categorize your app users by their functional roles. The tag choice is entirely up to you and depends on your use case. For example, you can use `type` to group users by their roles in your app, such as `moderator`, `player`, or `support-agent`. |

:::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).
:::

#### Output

| Type | Description |
| --- | --- |
| `Promise<User>` | Returned object containing the new [user](https://www.pubnub.com/docs/chat/chat-sdk/learn/chat-entities/user) data. |

#### Errors

If you try to create a user without providing their ID, you will receive the `ID is required` error. If you try to create a user that already exists, you will receive the `User with this ID already exists` error.

### Sample code

Create a user with an ID of `support_agent_15`. Specify their name, avatar, and custom attributes, such as their title and the LinkedIn profile URL.

```ts
// reference the "chat" object and invoke the "createUser()" method
const user = await chat.createUser(
    "support_agent_15",
    {
        name: "John Smith",
        profileUrl: "https://randomuser.me/api/portraits/men/1.jpg",
        custom: {
            title: "VP Marketing",
            linkedInUrl: "https://www.linkedin.com/mkelly_vp"
        }
    }
)
```