---
source_url: https://www.pubnub.com/docs/chat/swift-chat-sdk/build/features/users/create
title: Create users
updated_at: 2026-06-04T11:09:44.388Z
---

> 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/swift-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

This method takes the following parameters:

```swift
chat.createUser(
    id: String,
    name: String? = nil,
    externalId: String? = nil,
    profileUrl: String? = nil,
    email: String? = nil,
    custom: [String: JSONCodableScalar]? = nil,
    status: String? = nil,
    type: String? = nil
) async throws -> UserImpl
```

#### 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 | String: | 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

| Parameter | Description |
| --- | --- |
| `UserImpl` | `UserImpl` containing the newly created user object. |

### Sample code

:::tip Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
:::

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.

```swift
// Assumes a "ChatImpl" reference named "chat"
Task {
  let customAttributes: [String: JSONCodableScalar] = [
    "title": "Support Agent",
    "linkedin": "https://www.linkedin.com/in/support_agent_15"
  ]
  let user = try await chat.createUser(
    id: "support_agent_15",
    name: "John Doe",
    externalId: nil,
    profileUrl: nil,
    email: nil,
    custom: customAttributes,
    status: nil,
    type: nil
  )
}
```