# 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.

<codetabs>

<codetabs-item value="javascript" label="JavaScript">

```js
const client = stream.connect(
  "{{ api_key }}",
  "{{ feed_token }}",
  "{{ app_id }}",
);

// ensure the user data is stored on Stream
await client.setUser({
  name: "John Doe",
  occupation: "Software Engineer",
  gender: "male",
});
```

</codetabs-item>

<codetabs-item value="python" label="Python">

```python
# The Python API client exposes users methods on client.users
# when adding reactions, collections or reading feeds with enrichment
# you can provide `user_id` as an argument
```

</codetabs-item>

<codetabs-item value="ruby" label="Ruby">

```ruby
# The Ruby API client exposes user method on client.users
# when adding reactions, collections or reading feeds with enrichment
# you can provide `:user_id` as an argument
```

</codetabs-item>

<codetabs-item value="php" label="PHP">

```php
// The PHP API client exposes users methods on $client->users()
// when adding reactions, collections or reading feeds with enrichment
// you can provide `$user_id` as argument
```

</codetabs-item>

<codetabs-item value="java" label="Java">

```java
// Java API client exposes users methods on client.user object
// when adding reactions, collections you can provide `userID` as argument
```

</codetabs-item>

<codetabs-item value="go" label="Go">

```go
# The Go API client exposes users methods on Client.Users.
# When adding reactions, collections or reading feeds with enrichment
# you can provide `user_id` as an argument
```

</codetabs-item>

</codetabs>

## Adding Users

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.                                                                                                                            |

<codetabs>

<codetabs-item value="csharp" label="C#">

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

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

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

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
// create a new user, if the user already exist 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 exist the user is returned
client.user("john-doe").getOrCreate({
  name: "John Doe",
  occupation: "Software Engineer",
  gender: "male",
});
```

</codetabs-item>

<codetabs-item value="python" label="Python">

```python
# create a new user, if the user already exist 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 exist the user is returned
client.users.add(
  "john-doe",
  {"name": "John Doe", "occupation": "Software Engineer", "gender": "male"},
  get_or_create=True,
)
```

</codetabs-item>

<codetabs-item value="ruby" label="Ruby">

```ruby
# 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,
)
```

</codetabs-item>

<codetabs-item value="php" label="PHP">

```php
// 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);
```

</codetabs-item>

<codetabs-item value="java" label="Java">

```java
// create a new user, if the user already exist 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 exist the user is returned
client.user("john-doe").getOrCreate(new Data()
    .set("name", "John Doe")
    .set("occupation", "Software Engineer")
    .set("gender", "male")).join();
```

</codetabs-item>

<codetabs-item value="go" label="Go">

```go
// create a new user, if the user already exist an error is returned
	userData := stream.User{
		ID: "123",
		Data: map[string]any{
			"name":    "John Doe",
			"occupation": "Software Engineer",
			"gender":   "male",
		},
	}
	resp, err := client.Users().Add(context.TODO(), userData, false)
	if err != nil {
		panic(err)
	}

	// get or create a new user, if the user already exist the user is returned
	resp, err := client.Users().Add(context.TODO(), userData, true)
	if err != nil {
		panic(err)
	}
```

</codetabs-item>

</codetabs>

<admonition type="info">

The size of a user object can not exceed 10kB

</admonition>

## Retrieving Users

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

<codetabs>

<codetabs-item value="csharp" label="C#">

```csharp
await client.Users.GetAsync("123");
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
client.user("123").get();
```

</codetabs-item>

<codetabs-item value="python" label="Python">

```python
client.users.get("123")
```

</codetabs-item>

<codetabs-item value="ruby" label="Ruby">

```ruby
client.users.get("123")
```

</codetabs-item>

<codetabs-item value="php" label="PHP">

```php
$client->users()->get('42');
```

</codetabs-item>

<codetabs-item value="java" label="Java">

```java
client.user("123").get().join();
```

</codetabs-item>

<codetabs-item value="go" label="Go">

```go
resp, err := client.Users().Get(context.TODO(), "123")
	if err != nil {
		panic(err)
	}
```

</codetabs-item>

</codetabs>

## Removing Users

The delete endpoint removes a user by their ID.

<codetabs>

<codetabs-item value="csharp" label="C#">

```csharp
await client.Users.DeleteAsync("123")
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
client.user("123").delete();
```

</codetabs-item>

<codetabs-item value="python" label="Python">

```python
client.users.delete("123")
```

</codetabs-item>

<codetabs-item value="ruby" label="Ruby">

```ruby
client.users.delete("123")
```

</codetabs-item>

<codetabs-item value="php" label="PHP">

```php
$client-&gt;users()-&gt;delete('42');
```

</codetabs-item>

<codetabs-item value="java" label="Java">

```java
client.user("123").delete().join();
```

</codetabs-item>

<codetabs-item value="go" label="Go">

```go
resp, err := client.Users().Delete(context.TODO(), "123")
	if err != nil {
		panic(err)
	}
```

</codetabs-item>

</codetabs>

<admonition type="info">

When you delete a user it will be converted to a missing reference and throw an error when [enriching](/activity-feeds/docs/javascript/v2/#frontend_enrichment).

</admonition>

## Updating Users

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

### Parameters

| name | type   | description                  | default | optional |
| ---- | ------ | ---------------------------- | ------- | -------- |
| id   | string | The ID of the user to update | -       |          |
| data | object | The data related to the user | -       |          |

<codetabs>

<codetabs-item value="csharp" label="C#">

```csharp
var userData = new Dictionary<string, object>
{
  {"name", "Jane Doe" },
  {"occupation", "Software Engineer"},
  {"gender", "female"},
};
await client.Users.UpdateAsync("123", userData)
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
client.user("123").update({
  name: "Jane Doe",
  occupation: "Software Engineer",
  gender: "female",
});
```

</codetabs-item>

<codetabs-item value="python" label="Python">

```python
client.users.update("123",
  {"name": "Jane Doe", "occupation": "Software Engineer", "gender": "female"}
)
```

</codetabs-item>

<codetabs-item value="ruby" label="Ruby">

```ruby
client.users.update("123",
  :data => {:name => "Jane Doe", :occupation => "Software Engineer", :gender => "female"}
)
```

</codetabs-item>

<codetabs-item value="php" label="PHP">

```php
$user = $client-&gt;users()-&gt;update('42', array('name' =&gt; 'Arthur Dent');
```

</codetabs-item>

<codetabs-item value="java" label="Java">

```java
client.user("123").update(new Data()
    .set("name", "Jane Doe")
    .set("occupation", "Software Engineer")
    .set("gender", "female")).join();
```

</codetabs-item>

<codetabs-item value="go" label="Go">

```go
data := map[string]any{
		"name":    "John Doe",
		"occupation": "Software Engineer",
		"gender":   "female",
	}
	resp, err := client.Users().Update(context.TODO(), "123", data)
	if err != nil {
		panic(err)
	}
```

</codetabs-item>

</codetabs>


---

This page was last updated at 2026-03-13T13:11:07.125Z.

For the most recent version of this documentation, visit [https://getstream.io/activity-feeds/docs/go-golang/v2/users_introduction/](https://getstream.io/activity-feeds/docs/go-golang/v2/users_introduction/).