var updateUsersRequest = new UpdateUsersRequest{ Users = new Dictionary<string, UserRequest> { [_testUserId] = new UserRequest { ID = _testUserId, Name = "Test User 1", Role = "user" }, [_testUserId2] = new UserRequest { ID = _testUserId2, Name = "Test User 2", Role = "user" }, [_testUserId3] = new UserRequest { ID = _testUserId3, Name = "Test User 3", Role = "user" } }};var userResponse = await _client.UpdateUsersAsync(updateUsersRequest);
You can query and filter users using the queryUsers endpoint. This allows you to search for users based on various criteria such as custom fields, roles, and other user properties.
All filters use a Mongoose-style syntax; however, we do not run MongoDB on the backend, so only a subset of Mongoose queries are supported. The supported filters are described below.
var updateUsersRequest = new UpdateUsersRequest{ Users = new Dictionary<string, UserRequest> { [_testUserId] = new UserRequest { ID = _testUserId, Name = "Test User 1", Role = "user" }, [_testUserId2] = new UserRequest { ID = _testUserId2, Name = "Test User 2", Role = "user" }, [_testUserId3] = new UserRequest { ID = _testUserId3, Name = "Test User 3", Role = "user" } }};var userResponse = await _client.UpdateUsersAsync(updateUsersRequest);
Depending on your use case, you can choose to delete users or deactivate them. There are some differences between these two approaches.
Deactivating users:
the user will not be allowed to perform API requests / connect
user data is retained on Stream's side and returned from API
deactivated users can be re-activated
Deleting users:
the user will no longer be able to perform API requests / connect
the user is deleted and, by default, not returned from API
all data from the user is marked as deleted
by default, the data is retained and "soft" deleted; you can optionally request hard deletion
deletion is not reversible
Note: Both deletion and deactivation are performed asynchronously by Stream API. A task ID is returned and you can use that to check the status of its processing.
// Deactivating a single userclient.deactivateUser(testUserId, DeactivateUserRequest.builder().build()).execute();// Deactivating users in bulk is performed asynchronouslyDeactivateUsersRequest deactivateRequest = DeactivateUsersRequest.builder() .userIds(List.of(testUserId, testUserId2)) .build();client.deactivateUsers(deactivateRequest).execute();// Reactivate usersReactivateUsersRequest reactivateRequest = ReactivateUsersRequest.builder() .userIds(List.of(testUserId, testUserId2)) .build();client.reactivateUsers(reactivateRequest).execute();
// Deactivating a single user$client->deactivateUser( 'user1', new GeneratedModels\DeactivateUserRequest());// Deactivating users in bulk is performed asynchronously$response = $client->deactivateUsers( new GeneratedModels\DeactivateUsersRequest( userIds: ['user1', 'user2'] ));// Reactivate users$client->reactivateUsers( new GeneratedModels\ReactivateUsersRequest( userIds: ['user1', 'user2'] ));
// Deactivating a single userawait _client.DeactivateUserAsync(_testUserId, new DeactivateUserRequest());// Deactivating users in bulk is performed asynchronouslyvar deactivateRequest = new DeactivateUsersRequest{ UserIds = new[] { _testUserId, _testUserId2 }};await _client.DeactivateUsersAsync(deactivateRequest);// Reactivate usersvar reactivateRequest = new ReactivateUsersRequest{ UserIds = new[] { _testUserId, _testUserId2 }};await _client.ReactivateUsersAsync(reactivateRequest);
# Deactivating a single userself.client.deactivate_user(user_id=self.test_user_id)# Deactivating users in bulk is performed asynchronouslyresponse = self.client.deactivate_users( user_ids=[self.test_user_id, self.test_user_id_2])# Reactivate usersself.client.reactivate_users( user_ids=[self.test_user_id, self.test_user_id_2])
Deactivating users in bulk can take some time. This is how you can check the progress:
// Example of monitoring the status of an async task// The logic is same for all async tasksconst response = _; // Result of a Stream async API request// You need to poll this endpointconst taskResponse = await client.getTask({ id: response.task_id });console.log(taskResponse.status === "completed");
// Example of monitoring the status of an async task// The logic is same for all async tasksresponse, err := _ // Result of a Stream async API requestif err != nil { log.Fatal(err)}// You need to poll this endpointtaskResponse, err := client.GetTask(context.Background(), response.Data.TaskID, &getstream.GetTaskRequest{})if err != nil { log.Fatal(err)}fmt.Println(taskResponse.Data.Status == "completed")
// Example of monitoring the status of an async task// The logic is same for all async tasksvar response = _ // Result of a Stream async API request// You need to poll this endpointvar taskResponse = client.getTask(response.getTaskId()).execute().getData();System.out.println("completed".equals(taskResponse.getStatus()));
// Example of monitoring the status of an async task// The logic is same for all async tasks$response = _ // Result of a Stream async API request$taskId = $response->getData()->taskID;// you need to poll this endpoint$taskResponse = $client->getTask($taskId);echo $taskResponse->getData()->status === 'completed';
// Example of monitoring the status of an async task// The logic is same for all async tasksvar response = _ // Result of a Stream async API request// You need to poll this endpointvar taskResponse = await _client.GetTaskAsync(response.TaskID);Console.WriteLine(taskResponse.Status == "completed");
# Example of monitoring the status of an async task# The logic is same for all async tasksresponse = _ # Result of a Stream async API request# You need to poll this endpointtask_response = client.get_task(response.task_id)print(task_response.status == "completed")
# Example of monitoring the status of an async task# The logic is same for all async tasksresponse = _ # Result of a Stream async API request# You need to poll this endpointtask_response = client.get_task(response.data.task_id)puts task_response.data.status == 'completed'
Stream lets you give unauthenticated users access to a limited subset of Stream's capabilities. This is done by using either Guest or Anonymous users.
These two user types are ideal for use cases where users either need to be able to see feed activity prior to authenticating or in scenarios where the additional friction of creating a user account might be unnecessary for a user.
Configuration for guest and anonymous roles can be managed in the dashboard.
Guest sessions can be created client-side and do not require any server-side authentication. Use cases like support or public or visible feeds often benefit from guest users, because you may want a visitor to be able to view or interact with feeds on your application without (or before) having a regular user account. Guest users are temporary users.
Guest users are not available to applications using multi-tenancy (teams).
Guest users are counted towards your MAU usage.
You can generate a guest user in a front end client by using the following code:
import { FeedsClient } from "@stream-io/feeds-client";const client = new FeedsClient("<API key>");await client.connectGuest({ id: "tommaso" });
To create a guest user from your server and obtain a token for the client:
const response = await client.createGuest({ user: { id: "tommaso", name: "Tommaso" },});// Return response.user and response.access_token to your client
response, err := client.CreateGuest(context.Background(), &getstream.CreateGuestRequest{ User: getstream.UserRequest{ ID: "tommaso", Name: getstream.PtrTo("Tommaso"), },})if err != nil { log.Fatal("Error creating guest:", err)}// Return response.Data.User and response.Data.AccessToken to your client
CreateGuestRequest request = CreateGuestRequest.builder() .user(UserRequest.builder().id("tommaso").name("Tommaso").build()) .build();CreateGuestResponse response = client.createGuest(request).execute().getData();// Return response.getUser() and response.getAccessToken() to your client
$response = $client->createGuest(new GeneratedModels\CreateGuestRequest( user: [ 'id' => 'tommaso', 'name' => 'Tommaso', ]));// Return $response->user and $response->access_token to your client
var request = new CreateGuestRequest{ User = new UserRequest { ID = "tommaso", Name = "Tommaso" }};var response = await _client.CreateGuestAsync(request);// Return response.User and response.AccessToken to your client
response = self.client.create_guest( user=UserRequest(id="tommaso", name="Tommaso"))# Return response.user and response.access_token to your client
response = client.common.create_guest( GetStream::Generated::Models::CreateGuestRequest.new( user: { 'id' => 'tommaso', 'name' => 'Tommaso' } ))# Return response.user and response.access_token to your client
The user object schema is the same as the one described in the Built-in fields for users section above.
Creation of guest users can be disabled for your application in the dashboard.