Docs

Create a user

POST
/users

Creates a user whose attributes satisfy the user schema named in the request.

The server assigns the user's ID and returns it. schema is the id of a schema, as publishSchema (POST /schemas) returns it or listSchemas (GET /schemas) lists it. With team_id, the user also becomes an active member of that team. A value the schema marks unique that another user already holds is refused with 409; send a different value.

With team_id, the new user joins that team, which confers its roles: the team rule of createTeamMembership applies, answering 403 user.permission_denied when the caller does not pass it.

Authorization

headerAuthorizationBearer <token>

Scope: user.write

Query Parameters

project_id*string

The project ID: the id that createProject (POST /projects) returns. zitadel setup prints it as "Project id" in its summary and as project_id with --json, and writes it to .env.local as ZITADEL_PROJECT_ID.

Match^[a-zA-Z0-9_-]+$
team_id?string

Adds the new user to this team: creating the user also creates an active membership in it. Omit it to create a user with no memberships. Use the id that createTeam (POST /teams) returns or queryTeams (POST /teams/query) lists.

This is team membership, not lifecycle ownership. It does not decide who may deprovision the user, and the created user stays self-owned either way. The owning team is reported on reads as metadata.lifecycle_owner_team_id and cannot be set through this API.

The team also scopes team-unique attributes for this create: an attribute the schema marks unique per team is checked against this team's members.

Match^[a-zA-Z0-9_-]+$

Request Body

application/json
  1. body

The request body for creating a user: the schema it follows and the attributes that must satisfy that schema.

The server assigns the user's ID and returns it in the response, so the request carries no id. metadata is server-owned for the same reason. Neither is part of this schema, which is what frees a user schema to declare properties of those names.

A request carrying any other top-level property is rejected rather than ignored. attributes stays open, since the user schema determines what belongs in it.

schema*string

The ID of the schema that defines the content of attributes: the id that publishSchema (POST /schemas) returns or listSchemas (GET /schemas) lists. A default schema is provided.

Length1 <= length
attributes*

The user's schema-defined content. Validated against schema; a property the schema does not permit is rejected with req.invalid.

Response Body

The created user.

application/json
  1. response

A user is an individual identity in the system. It can represent a person, a service account or any other type of identity.

attributes is the document that satisfies the user schema named by schema. That schema defines its property names and types and validates it. The rest of the object (id, schema, metadata) is the server-owned envelope. Keeping the two apart means a schema may name a property id or metadata without colliding with the envelope. It also means closed-world keywords (additionalProperties: false, propertyNames, unevaluatedProperties) behave as their author expects.

id*user-id
Match^user_[a-zA-Z0-9_-]+$
schema*string

The ID of the schema that defines the content of attributes. getSchema (GET /schemas/{schema_id}) returns it, and publishSchema (POST /schemas) creates one.

attributes*

The user's content, satisfying the schema named by schema. Property names and types are determined entirely by that schema.

metadata*
identifier?string

The current value of the user schema's designated identifier (x-identifier), resolved when the user is read. Absent when the schema designates no identifier or the user carries no value for it.

identifier_property?string

The schema property identifier came from. With it, a client can read the property's definition for its meaning (a mailto link, a field label) instead of guessing from the value. Present exactly when identifier is.

display?string

The x-display rendering: the designated properties' values joined in list order, resolved when the user is read. It is for display only. Absent when the schema designates no display properties or the user carries no values for them. Clients render display, falling back to identifier, then id.

teams?array<>

The user's team memberships, present only when the request asked for them with expand: ["teams"]. Absent means it was not requested; [] means the user has none.

Memberships sit outside metadata: they are a related collection, not part of the server-owned envelope, and a different concept from metadata.lifecycle_owner_team_id, which names the one team that owns the user's lifecycle.

teams_truncated?boolean

True when the user is on more teams than the embedded list carries. The embedded list is capped and cannot be paged; read every team with listUserTeams (GET /users/{user_id}/teams). Present only alongside teams.

Example Request
import { 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 user = await api.createUser({ schema: "string", attributes: {} }, { project_id: "proj_01KWH1P4MYS7F0N9WD3P2E4YM5" });
Example Response
{  "id": "string",  "schema": "string",  "attributes": {},  "metadata": {    "created_at": "2019-08-24T14:15:22Z",    "updated_at": "2019-08-24T14:15:22Z",    "status": "active",    "lifecycle_owner_team_id": "string",    "lifecycle_owner_team": {      "id": "string",      "name": "string",      "status": "active",      "created_at": "2019-08-24T14:15:22Z",      "updated_at": "2019-08-24T14:15:22Z"    }  },  "identifier": "string",  "identifier_property": "string",  "display": "string",  "teams": [    {      "id": "string",      "name": "string",      "membership_status": "pending",      "created_at": "2019-08-24T14:15:22Z",      "updated_at": "2019-08-24T14:15:22Z"    }  ],  "teams_truncated": true}

Was this helpful?