Docs

Update a user by ID

PATCH
/users/{user_id}

Partially updates a user's schema-defined attributes, and optionally moves the user to another registered schema. The merged result is validated against the schema before commit. Concurrent writes are last-write-wins.

To move the user, send schema with the id of a registered schema, as publishSchema (POST /schemas) returns it or listSchemas (GET /schemas) lists it.

To ask whether a patch would succeed, send it with "dry_run": true. It takes the same permission and answers the same status and details as the real request, and it changes nothing and emits no user.updated. The request itself is still recorded as request.api, like any other API call. A 200 holds for the moment of the check: a unique value that is free then can be taken before the real request, which then answers 409.

dry_run is a body field so that a server from before it refuses the request as malformed (400 req.invalid) instead of applying the patch.

Authorization

headerAuthorizationBearer <token>

Scope: user.write

Path Parameters

user_id*string

The user ID: the id that createUser (POST /users) or queryUsers (POST /users/query) returns.

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

Request Body

The changes to merge into the user.

application/json
  1. body

A partial update, merged into the user's current state. At least one of schema and attributes must be present; an empty patch is rejected with user.invalid.

attributes is merged key by key into the stored attributes: an omitted key stays untouched, an object merges recursively, null deletes the attribute, and any other value replaces the stored one. The merged result is validated as a whole against the user's schema, so a patch that deletes or invalidates a required property is rejected with req.invalid.

schema moves the user to another registered schema, which is how a user upgrades to a newer schema revision. The target must be a revision of the user's current schema (the same objectType), newer or older; a schema of another objectType is rejected with user.invalid. A schema stored without an objectType is a revision of nothing, so a user cannot move to or from one. The request must be self-contained: merged attributes are validated against the new schema before commit, and every uniqueness claim is recomputed under the new schema's annotations. Values removed by an earlier move are not restored by moving back.

Properties1 <= properties
schema?string

The ID of the schema the user follows after this patch: the id that publishSchema (POST /schemas) returns or listSchemas (GET /schemas) lists. Omit it to keep the current schema. The schema must already be registered and be a revision of the user's current schema.

Length1 <= length
dry_run?boolean

Set to true to check the patch without applying it. The response is what the real request would answer now; a 200 holds the user as the patch would leave them, with metadata.updated_at unchanged. Leave it out to apply the patch. A server from before this field refuses the request with 400 and changes nothing.

attributes?

The changed attributes only. null deletes an attribute; omitted keys are untouched.

Properties1 <= properties

Response Body

The updated user, or with dry_run the user as the patch would leave them.

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 { configureZitadel, getApi } from "@zitadel/api/config";import { setApiCsrfToken } from "@zitadel/api/runtime/auth";// In the browser, through the SDK proxy: the session cookie authenticates the call.const client = getApi(configureZitadel({ projectId: "proj_01KWH1P4MYS7F0N9WD3P2E4YM5" }));// A write the session cookie authenticates carries the session's CSRF token.setApiCsrfToken((await client.getMySessionCsrfToken()).csrf_token);const user = await client.updateUser("user_01KWH3B72K7M7F0N9WD3P2E4YM", {});
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?