Skip to content
Add a user to a group

Add a user to a group

Add a represented user to a group and keep their other groups. An unknown user is created.

PUT/api/v1/users/:userId/groups/:groupId

Request#

TypeScript
const response = await fetch("https://api.smallworld.sh/api/v1/users/customer_123/groups/team_42", {
  method: "PUT",
  headers: { Authorization: `Bearer ${apiKey}` },
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
const result = await response.json();

Use your server-side apiKey. Replace the example IDs.

Path parameters#

userIdstringrequired

Your application's user ID, URL-encoded. At most 512 characters, with no surrounding whitespace or null bytes. Encode the IDs . and .. as %2E and %2E%2E: curl sends these as written, but JavaScript's fetch removes them even when encoded.

groupIdstringrequired

Your application's group ID, URL-encoded. At most 512 characters, with no surrounding whitespace or null bytes.

Responses#

Returns id, nullable email, groupIds, and ISO 8601 createdAt and updatedAt timestamps. The ID is your application's identifier; groupIds lists your IDs for the user's current groups, ordered by ID, and is empty when they belong to none.

200 response
{
  "id": "customer_123",
  "email": "customer@example.com",
  "groupIds": [
    "team_42",
    "team_77"
  ],
  "createdAt": "2026-10-10T12:00:00.000Z",
  "updatedAt": "2026-10-10T12:00:00.000Z"
}
More about this endpoint

The user keeps their other groups. A user can belong to any number of groups.

Adding a user to a group they are already in changes nothing, so a retry is safe.

An unknown userId is created without an email. The group must already exist; for an unknown group, nothing is created.

The user's open sessions are not affected: each keeps the group it was created for, and a groupless session stays groupless. Once the user belongs to several groups, a new session needs groupId in POST /worlds/:worldId/execute, and reads such as GET /users/:userId/connections need ?groupId=.

The Playground user belongs only to the Playground Group, and no other user can join the Playground Group.