On this page

Create users

CreateUser() creates a new user (User object) with a unique User ID.

Requires App Context

To store data about users, you must enable App Context for your app's keyset in the Admin Portal.

Method signature

This method takes the following parameters:

1chat.CreateUser(
2 string userId,
3 ChatUserData? additionalData = null
4)
5
6public class ChatUserData
7{
8 public string Username { get; set; } = string.Empty;
9 public string ExternalId { get; set; } = string.Empty;
10 public string ProfileUrl { get; set; } = string.Empty;
11 public string Email { get; set; } = string.Empty;
12 public Dictionary<string, object> CustomData { get; set; } = new ();
13 public string Status { get; set; } = string.Empty;
14 public string Type { get; set; } = string.Empty;
15}

Input

* required
ParameterDescription
userId *
Type: string
Default:
n/a
Unique user identifier.
Username
Type: string
Default:
string.Empty
Display name for the user (must not be empty or consist only of whitespace characters).
ExternalId
Type: string
Default:
string.Empty
User's identifier in an external system. You can use it to match id with a similar identifier from an external database.
ProfileUrl
Type: string
Default:
string.Empty
URL of the user's profile picture.
Email
Type: string
Default:
string.Empty
User's email address.
CustomData
Type: Dictionary<string, object>
Default:
new ()
JSON providing custom data about the user. Values must be scalar only; arrays or objects are not supported. Filtering App Context data through the CustomData property is not recommended in SDKs.
Status
Type: string
Default:
string.Empty
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
Type: string
Default:
string.Empty
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.
API limits

To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.

Output

TypeDescription
Task<ChatOperationResult<User>>
An awaitable Task with the returned object containing the new user data.

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.

1

Last updated on