Adding Users

Last Edit: Feb 02 2020

This endpoint allows you to insert a new user.

Name

Type

Description

id

string

The unique identifier for the new user (eg. username, user id, etc.). The value is restricted to alphanumeric characters, dashes and underscore symbols.

data

object

The data related to the user.


// create a new user, if the user already exists an error is returned
client.user("john-doe").create({
    name: "John Doe", 
    occupation: "Software Engineer",
    gender: 'male'
});

// get or create a new user, if the user already exists the user is returned
client.user("john-doe").getOrCreate({
    name: "John Doe", 
    occupation: "Software Engineer",
    gender: 'male'
});
                    

# create a new user, if the user already exists an error is returned
client.users.add(
    "john-doe",
    {"name": "John Doe", "occupation": "Software Engineer", "gender": "male"},
)

# get or create a new user, if the user already exists the user is returned
client.users.add(
    "john-doe",
    {"name": "John Doe", "occupation": "Software Engineer", "gender": "male"},
    get_or_create=True,
)
                    

# create a new user, if the user already exists, an error is returned
client.users.add(
    "john-doe", 
    :data => {:name => "John Doe", :occupation => "Software Engineer", :gender => "male"},
)

# get or create a new user, if the user already exists, the user is returned
client.users.add(
    "john-doe", 
    :data => {:name => "John Doe", :occupation => "Software Engineer", :gender => "male"},
    :get_or_create => true,
)
                    

// create a new user with the name in userdata
$user = $client->users()->add('42', array('name' => 'Arthur Dent'));
// get OR create the user
$user = $client->users()->add('42', array('name' => 'Arthur Dent'), true);
                    

// create a new user, if the user already exists an error is returned
client.user("john-doe").create(new Data()
        .set("name", "John Doe")
        .set("occupation", "Software Engineer")
        .set("gender", "male")).join();

// get or create a new user, if the user already exists the user is returned
client.user("john-doe").getOrCreate(new Data()
        .set("name", "John Doe")
        .set("occupation", "Software Engineer")
        .set("gender", "male")).join();
                    

// create a new user, if the user already exists an error is returned
userData := stream.User{
	ID: "john-doe",
	Data: map[string]interface{}{
		"name":       "John Doe",
		"occupation": "Software Engineer",
		"gender":     "male",
	},
}
user, err := client.Users().Add(userData, false)

// get or create a new user, if the user already exists the user is returned
user, err = client.Users().Add(userData, true)
                    

// create a new user, if the user already exists an error is returned
client.create(user: User(id: "john-doe"), getOrCreate: false) { result in /* ... */ }

// get or create a new user, if the user already exists the user is returned
client.create(user: User(id: "john-doe"), getOrCreate: true) { result in /* ... */ }
                    

// create a new user, if the user already exists an error is returned
const userData = new Dictionary<string, object>()
{
    {"name", "John Doe" },
    {"occupation", "Software Engineer"},
    {"gender", "male"},
};

await client.Users.Add("john-doe", userData);

// get or create a new user, if the user already exists the user is returned
await client.Users.Add("john-doe", userData, true);