Users

Stream allows you to store user information and embed them inside activities or use them for personalization. When stored in activities, users are automatically enriched by Stream.

let client = Client(apiKey: "c38bmrz86x8y", appId: "64184", token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidXNlcjEifQ.BQudnXB4B8wyoVDW403IaRG3zDs31L65VrVtf87prho")
let user = User(id: "john-doe")

client.create(user: user) { result in
  if let createdUser = try? result.get() {
    client.currentUser = createdUser
  }
}

Adding Users

This endpoint allows you to insert a new user.

NameTypeDescription
idstringThe unique identifier for the new user (eg. username, user id, etc.). The value is restricted to alphanumeric characters, dashes and underscore symbols.
dataobjectThe data related to the user.
// create a new user, if the user already exist 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 exist the user is returned
client.create(user: User(id: "john-doe"), getOrCreate: true) { result in /* ... */ }

The size of a user object can not exceed 10kB

Retrieving Users

The retrieving users endpoint allows you to retrieve a user by their ID.

client.get(userId: "123") { result in /* ... */ }

Removing Users

The delete endpoint removes a user by their ID.

client.delete(userId: "123") { result in /* ... */ }

When you delete a user it will be converted to a missing reference and throw an error when enriching.

Updating Users

This endpoint allows you to update a user by their ID.

Parameters

nametypedescriptiondefaultoptional
idstringThe ID of the user to update-
dataobjectThe data related to the user-
client.update(user: User(id: "john-doe")) { result in /* ... */ }
© Getstream.io, Inc. All Rights Reserved.