On this page

Create users

Use CreateUser() to create a new User with a unique User ID.

Requires App Context

Enable App Context on your keyset in the Admin Portal to store user data.

icon

Usage in Blueprints and C++


Method signature

API limits

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

Output

TypeDescription
UPubnubUser*
Returned object containing the new 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.

1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9// Define user data
10FString UserID = "UniqueUser123";
11
12FPubnubChatUserData UserData;
13UserData.UserName = "JohnDoe";
14UserData.ExternalID = "External123";
15UserData.ProfileUrl = "http://example.com/profile/johndoe.jpg";
show all 22 lines
Last updated on