Create a team membership
Adds an existing user of the team's project to the team as an active member.
The caller needs the admin role on the team's project: a member of a team
that owns a project, or that holds a grant, gets that team's role.
The request is idempotent. Adding a user who is already an active member
answers 201 with the membership and changes nothing. Adding a user who
was removed makes the membership active again and keeps its created_at.
Each change sends a team.membership.updated event.
The team must be active: a deactivated team answers 404 team.team_not_found.
A user who is not active is refused with 409 team.user_not_active:
reactivate the user first.
A membership confers the team's roles
(ADR 094 §7).
For a team of the deployment's platform project, the caller must hold, on
every project the team owns or holds a grant on, at least the role it gives
(owning a project gives admin), or the call answers 403 with
details.details.reason target_holds_more; to a team that owns a
project, only one of its active members or an operator adds a member, not
an admin of the team's own project (reason owning_team_members_only).
The one exception: on a deployment that names no operator, an admin of
the platform project adds a member to such a team that has no active
member (ADR 054 §8),
and the request's events carry metadata.authorization.path
owning_team_recovery. A team of any other project is that project's to
manage.
AuthorizationBearer <token>Scope: team_membership.create
team_id*stringThe team ID: the id that createTeam (POST /teams) or queryTeams (POST /teams/query) returns.
^[a-zA-Z0-9_-]+$application/json- body
user_id*user-idThe user to add: the id that createUser (POST /users) or
queryUsers (POST /users/query) returns. The user must be active and
belong to the team's project.
^user_[a-zA-Z0-9_-]+$The user is an active member of the team.
application/json- response
A user's membership of a team.
team_id*stringThe team the user belongs to.
user_id*stringThe user who belongs to the team.
status*stringThe user's participation state on the team.
"pending""active""inactive"created_at*stringThe time when the user was first added to the team. Adding a user again after a removal keeps it.
date-timeupdated_at*stringThe time when the membership last changed.
date-timeimport { createZitadelApi } from "@zitadel/api/client";import { configureZitadel, getApi } from "@zitadel/api/config";// In the browser, through the SDK proxy: the session cookie authenticates the call.const session = getApi(configureZitadel({ projectId: "proj_01KWH1P4MYS7F0N9WD3P2E4YM5" }));// A write the session cookie authenticates carries the session's CSRF token.const { csrf_token } = await session.getMySessionCsrfToken();const api = createZitadelApi( session.client.with({ fetch: (input, init) => { const headers = new Headers(init?.headers); headers.set("X-Zitadel-CSRF", csrf_token); return fetch(input, { ...init, headers }); }, }),);const teamMembership = await api.createTeamMembership( "team_01KZZY8PX8K8ATNVDSMRCZY4N1", { user_id: "string" },);{ "team_id": "string", "user_id": "string", "status": "pending", "created_at": "2019-08-24T14:15:22Z", "updated_at": "2019-08-24T14:15:22Z"}Was this helpful?