# Organization management

See [organization invitations and applications](https://m7.org/docs/api/api.user.m7.org/org-relationships.md) for consent-based Management enrollment.

Organization IDs in these routes remain native org UUIDs. The shared org service
also ensures a stable canonical M7 principal reference during creation, in the
same transaction as the org and any Management setup. That reference is currently
for principal lists, rosters, and external resource ownership. Ordinary org
responses do not acquire a `principal_id` field. Authorized SSO
[`/userinfo/orgs`](https://m7.org/docs/api/sso.user.m7.org/userinfo-orgs.md) exports
it alongside the native ID and ensures it for older orgs. Registration grants no
membership, delegation, or authority to act for the org.

Organizations are first-class identities. A consumer account can belong to
several organizations through each org's implicit **Management** group. Tenant
accounts remain inside their own organization and ordinary tenant/client groups;
those groups are distinct from organization management access.

Use the routes below to manage organizations, Management access, ordinary groups,
and tenant accounts. Paths are relative to `https://api.user.m7.org/api/v2`.
Send POST JSON unless stated otherwise, with the credential and sender bindings
required by [authorization](https://m7.org/docs/api/api.user.m7.org/authorization.md). Example UUIDs are valid illustrative
identifiers; substitute records from your organization. An organization member record is called a
*member* in this guide even though its route path is `/org/client/*`.

## Authentication

The [member Security operations](https://m7.org/docs/api/api.user.m7.org/tenant-member-security.md) are a narrower
human-manager-only contract: they reject machine and tenant-member credentials.
They require current Management membership with role `owner` or `admin`.
Other organization routes follow the rules below.

A human caller uses a consumer-user access token and must have active access in
the organization's Management group. An organization-member access token does
not, by itself, authorize these management routes.

Ordinary client-credentials application tokens are accepted by eligible org
routes for organizations where the app itself has active Management membership
and a live human Management member remains. This includes personal and org-owned
registrations backing either directory mode. Registration ownership, tenant and
creator access do not supply that membership. An application cannot create an
organization. See the [authorization guide](https://m7.org/docs/api/api.user.m7.org/authorization.md) for
the complete human- and machine-principal rules.

### Organization roles

The API checks the caller's live stored Management role, independently of the
frontend and OAuth scopes. Request fields cannot select the acting principal.

| Operation | Owner | Admin | Member |
| --- | --- | --- | --- |
| Read org identity/public Data and own permissions | Yes | Yes | Yes |
| Edit org properties, policy, lifecycle or org identity credentials | Yes | No | No |
| Read/manage discovery policy, membership roles/pub and management scope tags/data | Yes | No | No |
| Read/manage org client applications and API keys | Yes | No | No |
| Manage tenant accounts, ordinary groups and tenant group memberships | Yes | Yes | No |
| Leave the org voluntarily | No; change role first | Own membership only | Own membership only |

Admins and members read their own `management_access` through `/org/get` or
`/org/search`; these contain their membership ID/role, public `pub`, and assigned
tags with tag definition `data`. Membership `pri` and other principals are not
included. Members receive basic org fields, including `owner` and public `data`,
without org configuration. Admin configuration omits the owner-only `discovery_policy`.
Admin scope delegation and admin read-only app/key inventory are deferred;
owners create Management memberships and assign scopes. Legacy `viewer` access
was migrated operationally to `member`; current API and frontend inputs reject
`viewer`. This restriction concerns org access, not every shared group role or
database role enum. Members' assigned duties are primarily enforced by consuming
services. [OAuth applications](https://m7.org/docs/api/api.user.m7.org/oauth-clients.md) and [API keys](https://m7.org/docs/api/api.user.m7.org/api-keys.md) require
the live stored owner role even when the caller created the asset; matching
creator attribution, request-supplied actors, OAuth scopes, and frontend visibility
cannot grant authority. Last-owner protection remains.

Tenant accounts, ordinary groups and group memberships require owner/admin
authority before tenant setup. Eligible organization machines use their own
Management principal and require an active human manager; the eight
[tenant security actions](https://m7.org/docs/api/api.user.m7.org/tenant-member-security.md) require a human consumer
owner/admin and recheck that role under the grant lock.

## Organization routes

| Route | Required fields | Optional fields and behavior |
| --- | --- | --- |
| `/org/search` | None | `archived` boolean. Returns organizations the caller belongs to, with the role-specific projection above. |
| `/org/insert` | `name` | `slug`, `description`, `data`, `status`, `expires`. A blank `slug` is generated. The owner is always the token principal; machine applications cannot create organizations. |
| `/org/get` | `id` | Returns the role-specific org projection; owners/admins also receive `config` and `knobs`. |
| `/org/leave` | `org`, `confirm: true` | POST only, human consumer only. Removes the caller's own admin/member Management membership and its assigned tags/metadata. Owners cannot leave through this route. |
| `/org/update` | `id` | Partial update of the standard organization fields. Does not modify policy knobs. |
| `/org/set_knobs` | `id` | Send only policy fields to change. `null` or `""` clears an optional override. |
| `/org/discovery/get` | `id` | Owner only. Returns `id`, `policy`, `client_org_release`, and `client_org_userinfo_disclosure`; scope `org.get`. Missing configuration returns both membership-discovery switches off, an empty ACL, release false, and UserInfo disclosure `never`. |
| `/org/discovery/set` | `id`, `policy` | Owner only. Replaces the complete discovery policy atomically; optional `client_org_release` and `client_org_userinfo_disclosure` preserve their current values when omitted. Scope `org.set_knobs`. |
| `/org/delete` | `id` | Archives or deletes the organization. |
| `/org/restore` | `id` | Restores a previously archived organization. |
| `/org/identity/get` | `org` | `oid` is an alias; `vendor` defaults to `m7`. An organization with no identity returns `rid: null` and `active: false`. |
| `/org/identity/set` | `org` | `vendor` defaults to `m7`; use `active` to set state. Creating or recreating a missing child also requires `pass` and `confirm`. |

### Organization discovery policy

The owner controls whether `/userinfo/orgs` discloses this organization to the
app identified by the caller's validated token. Any requesting app may be
personal or org-owned. A caller still needs its own live Management membership;
an allow rule grants disclosure, not membership or product access. Owner/admin
roles do not bypass a discovery denial.
SSO returns permitted existing facts only when the caller requests discovery;
this policy does not push organizations into a consuming server.

User M7 orders **Access** as **Members**, initially selected, then **Policy**.
Returning to Access preserves the selected subtab. Policy has two independent
switches, both off by default, plus an ordered access list. Members retains
principals, roles, membership public data and the tag picker. Only stored owners
may load or save Policy; admins and members cannot decide enrollment or disclosure.

```json
{
  "id": "11111111-1111-4111-8111-111111111111",
  "policy": {
    "discoverable": false,
    "same_org_discoverable": false,
    "acl": [
      {"type": "app", "client_id": "example-consumer-app", "policy": "deny"},
      {"type": "org", "id": "33333333-3333-4333-8333-333333333333", "policy": "allow"}
    ]
  }
}
```

POST this body to `/api/v2/org/discovery/set`. Policy-read requests use the same
`id`, for example `{"id":"11111111-1111-4111-8111-111111111111"}`.
Both routes use POST JSON and the standard envelope. A successful get uses
`status: 1`, `comment: "OK"`; a successful set uses `status: 1`,
`comment: "SAVED"`. In each case `data` contains `id` and the complete projected
`policy`, plus `client_org_release` and `client_org_userinfo_disclosure`,
not the bare policy object. For example, the saved response is:

```json
{
  "status": 1,
  "comment": "SAVED",
  "data": {
    "id": "11111111-1111-4111-8111-111111111111",
    "policy": {
      "discoverable": false,
      "same_org_discoverable": false,
      "acl": [
        {"type": "app", "id": "22222222-2222-4222-8222-222222222222", "client_id": "example-consumer-app", "policy": "deny", "name": "Example consumer app", "available": true},
        {"type": "org", "id": "33333333-3333-4333-8333-333333333333", "policy": "allow", "name": "Example partner", "available": true}
      ]
    },
    "client_org_release": false,
    "client_org_userinfo_disclosure": "never"
  }
}
```

The routes reuse `org.get` and `org.set_knobs` scope policies respectively,
including the existing first-party exemption; scopes do not bypass owner checks.
Validation/authorization failures use `status: 0` and a safe `comment` in the
[standard error envelope](https://m7.org/docs/api/api.user.m7.org/README.md#request-and-response-format). Invalid input,
unknown targets or stale bindings leave the stored policy unchanged; storage
failure must be handled as an error. A missing policy entry after a successful
storage read returns both switches off and `acl: []`.

Rule `type` is `app` or `org`; `policy` is `allow` or `deny`. App rules
accept the public OAuth `client_id` (nonblank, at most 128 bytes, not necessarily
a UUID). The backend looks up that registration and stores its internal row
UUID. Org rules accept a non-nil organization UUID as `id` and require the org
to exist. Unknown apps or orgs reject the complete save before any policy write.
An org rule matches the requesting app's current owning `org`.
The first matching rule wins regardless of type; repeated targets
are permitted and retain that order. The list allows at most 200 rules.

Both get and set responses include each target's live `name` and `available`
flag. App rows also include their public `client_id` and bound internal `id`.
The frontend displays Client IDs and labels; its internal binding is hidden.
Labels are read-only and never trusted from request input. Existing stored
internal rules reload with public IDs without migration. An unavailable target
has `available: false` and a null name (and null app Client ID); replace it or
remove the rule. It is never silently reinterpreted as a public ID.

When resubmitting an unchanged app rule, its returned `id` may accompany
`client_id`. If that Client ID now identifies another registration, the save
fails and requires a reload. Changing the target explicitly sends the new
Client ID for fresh binding. Names are resolved before writing, so failed
target lookup cannot produce a partially saved policy.

If no rule matches, an app with a non-nil owning org equal to this org uses
`same_org_discoverable`; all other apps use `discoverable`. Same-org apps do not
inherit the outside switch. An explicit deny overrides either fallback. Both
switches must be JSON booleans; omitted fields receive default-off values.
Unknown fields and malformed rules are rejected.

Storage uses one JSON `discovery_policy` entry in existing `organization_config`;
saves preserve unrelated configuration. No new table or column is required.
Existing organizations without this entry are hidden from discovery until an
owner opts in. An absent policy entry is valid default-off configuration; an
unavailable table, failed read/write, or invalid saved policy is an error. Such
failures fail the SSO lookup; it never returns
a successful empty list as a substitute for a failed policy read. Denied orgs
are omitted with their memberships, public data, tags and app inventories.

### Application organization disclosure

The same owner-only discovery routes manage two additional settings outside
the nested `policy` object:

| Field | Contract |
| --- | --- |
| `client_org_release` | JSON boolean, default false. Allows newly issued access tokens for org-owned apps to contain informational `client.org` and `client.tenant` descriptors. |
| `client_org_userinfo_disclosure` | Exact string `always`, `acl`, or `never`; default `never`. Controls the issuing registration’s `client` summary in the live SSO organization response. |

Send the required complete `policy` with any settings to change. Omission
preserves each current additional setting; null or a wrong type/value is
rejected. Policy and supplied settings save atomically, preserving unrelated
organization configuration. Get and set return the effective values.

`always` exposes the eligible org-owned registration’s summary; `never`
returns `client: null`; `acl` applies the existing ordered disclosure policy
to the requesting registration. Recipient-authenticated
[organization introspection](https://m7.org/docs/api/sso.user.m7.org/userinfo-orgs.md#receiving-service-organization-lookup)
instead applies it to the authenticated recipient. These modes control the
registration summary independently of the caller’s `orgs` membership list,
which always remains subject to membership and ordered discovery policy.

Token release and live UserInfo disclosure are separate choices. Token
release describes the registration’s owning organization and optional tenant
directory; it grants no membership, resource access, role, or delegation.
Changing it does not redact already-issued tokens. Personal registrations
have no org owner to release. See the
[token ownership descriptor](https://m7.org/docs/api/sso.user.m7.org/token-formats.md#optional-application-ownership)
and [live response projection](https://m7.org/docs/api/sso.user.m7.org/userinfo-orgs.md#current-projection).

### Leave an organization

The shared Properties/Permissions modal offers **Leave organization** to admins
and members, with a confirmation prompt. After success, the modal closes and the
org list refreshes; leaving from the workspace returns to the org list.

```http
POST /api/v2/org/leave HTTP/1.1
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{"org":"11111111-1111-4111-8111-111111111111","confirm":true}
```

The API derives the membership from the authenticated consumer. It accepts no
`principal`, `membership`, `role`, or other target selector. Confirmation must
be JSON boolean `true`. Scoped third-party callers require `org.leave` under
the standard route-scope policy; the first-party panel exemption still applies.
Eligible tokens must pass the existing session, audience and sender-binding
checks. Machine and tenant-member credentials cannot use this operation.

Owners must have their role changed to admin/member before leaving, even when
another owner exists. The stored role and membership are rechecked while holding
the same lock used by role changes. Removal of membership, assigned tag junctions
and membership metadata (including `pub`/`pri`) is atomic. Tag definitions,
other principals and membership of another org are preserved. The operation
does not delete the org or the user's account. The next live org lookup/export
omits the departed org for this consumer. Cleanup runs in one transaction:
delete this membership's tag junction rows, delete its metadata (`pub` and `pri`),
then delete the Management membership. Failure to delete or commit rolls back
all of that cleanup; the global principal also survives. Rejoining requires an owner to add the user;
the new membership does not inherit old assignments or data.

Success uses the ordinary API envelope, `comment: "Organization left"`, and
`data.org`. Failure uses the [standard error envelope](https://m7.org/docs/api/api.user.m7.org/README.md): examples
include `Confirm leaving the organization`,
`Owners must change their access level before leaving an organization`,
`Management membership changed; reopen the organization`, and
`Management membership is busy; retry`. Do not treat a failed cleanup as success.
The UI asks for confirmation; Cancel sends nothing. Failures keep the modal open
and restore the button for retry. No membership expiry feature was added.

### Create an organization

```bash
curl -sS https://api.user.m7.org/api/v2/org/insert \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Example Org",
    "slug": "example-org",
    "description": "Example organization"
  }'
```

```json
{
  "status": 1,
  "comment": "INSERT",
  "data": {
    "id": "11111111-1111-4111-8111-111111111111",
    "name": "Example Org",
    "slug": "example-org",
    "status": "active"
  }
}
```

## Organization policy knobs

See [tenant policy](https://m7.org/docs/api/api.user.m7.org/tenant-policy.md) for browser-direct authentication,
registration and email-sign-in fields, and the org-only multiple-identity,
two-factor and email-two-factor switches. These organization boolean fields
require explicit booleans; the optional-override clearing rule does not apply.

`/org/set_knobs` is the policy endpoint. Send `id` plus only the fields to
change. The response comment is `SET_KNOBS` and the response includes the
resolved `config` and `knobs` maps.

### Token policy fields

Each token family supports a default TTL, lower and upper bound, mutability
flag, default claim object, and claim mutability flag:

```text
access_token_ttl_default          access_token_ttl_min
access_token_ttl_max              access_token_ttl_mutable
access_token_claims               access_token_claims_mutable
refresh_token_ttl_default         refresh_token_ttl_min
refresh_token_ttl_max             refresh_token_ttl_mutable
refresh_token_claims              refresh_token_claims_mutable
client_credentials_token_ttl_default  client_credentials_token_ttl_min
client_credentials_token_ttl_max      client_credentials_token_ttl_mutable
client_credentials_claims             client_credentials_claims_mutable
```

- TTL values are positive integer seconds.
- `*_mutable` values are booleans.
- `*_claims` values are JSON objects (an object or a JSON-encoded object).
- Send `null` or `""` to remove an optional value.

### Application-policy fields

Organization policy fields use the `tenant_policy_*` prefix. The accepted
names cover public registration, federated sign-in, hosted registration, and
hosted branding:

```text
tenant_policy_allow_public_registrations
tenant_policy_allow_federated_signin
tenant_policy_hosted_allow_public_registrations
tenant_policy_hosted_registration_email_requirement
tenant_policy_hosted_registration_display_name_requirement
tenant_policy_hosted_registration_email_verification
tenant_policy_hosted_registration_phone_requirement
tenant_policy_hosted_registration_phone_verification
tenant_policy_hosted_registration_password_requirement
tenant_policy_hosted_registration_first_name_requirement
tenant_policy_hosted_registration_last_name_requirement
tenant_policy_hosted_registration_username_requirement
tenant_policy_hosted_registration_include_tenant_terms_in_consent
tenant_policy_hosted_registration_human_verification_requirement
tenant_policy_hosted_registration_activation_mode
tenant_policy_hosted_registration_activation_rule
tenant_policy_hosted_registration_activation_methods
tenant_policy_hosted_registration_send_welcome_email
tenant_policy_hosted_branding_display_name
tenant_policy_hosted_branding_hero_logo_url
tenant_policy_hosted_branding_compact_logo_url
tenant_policy_hosted_branding_home_url
tenant_policy_hosted_header_hero_show_logo
tenant_policy_hosted_header_hero_show_name
tenant_policy_hosted_header_compact_show_logo
tenant_policy_hosted_header_compact_show_name
tenant_policy_hosted_branding_color_primary
tenant_policy_hosted_branding_color_background
tenant_policy_hosted_branding_color_surface
tenant_policy_hosted_branding_support_url
tenant_policy_hosted_branding_terms_url
tenant_policy_hosted_branding_privacy_url
```

Boolean policy fields accept JSON booleans. URL values require absolute HTTPS
URLs where applicable, colors use CSS hex values, and
`tenant_policy_hosted_registration_activation_methods` accepts `email`,
`phone`, or `email,phone` and is returned as an array.

### Set a token-policy default

```bash
curl -sS https://api.user.m7.org/api/v2/org/set_knobs \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "id": "11111111-1111-4111-8111-111111111111",
    "access_token_ttl_default": 900
  }'
```

## Management group

`/org/manage/*` manages the built-in **Management** group. It is distinct from
ordinary organization groups. All these routes require the current stored
`owner` role. Every request must use only the fields shown below; other fields
are rejected.

| Route | Required fields | Optional fields and behavior |
| --- | --- | --- |
| `/org/manage/search` | `org` | `role` plus shared pagination fields. |
| `/org/manage/get` | `org`, `principal` | Returns one Management membership. |
| `/org/manage/add` | `org`, `principal`, `type`, `role` | `type` is `user`, `app`, or `delegate`. |
| `/org/manage/set` | `org`, `principal`, `role` | Optional `pub` and `membership` (required when supplying `pub`). Saves role and public membership data together. |
| `/org/manage/remove` | `org`, `principal` | Removes a membership, its tags, and its membership metadata only when an owner remains. |
| `/org/manage/set_tags` | `org`, `principal`, `membership`, `tag_ids` | Replaces the tags assigned to this exact Management membership. An empty array clears them. |

Allowed role values are `owner`, `admin`, and `member`; they enforce the
authority matrix above. At least one `owner` must remain when a membership is
changed or removed.

### Three separate data locations

| Location | Ownership and use |
| --- | --- |
| `organization.data` | Organization-level service-readable data, shown in Properties. It is separate from caller membership facts and is not included in `/userinfo/orgs`. |
| `organization_manage_group_meta.pub` | Public JSON for one Management membership, with `asset` set to that membership UUID. Only `pub` is exposed/edited; `pri` is preserved during updates and never exported. |
| Tag definition `data` | JSON on one scope tag, shared by its assignments inside the org's tag pool. It is not the membership's `pub`. |

On org creation, omitted, blank, whitespace-only or null `data` becomes `{}`;
on update, omitted `data` preserves storage, while blank/whitespace/null becomes
`{}`. Org Data is visible in the read-only Properties modal and omitted from
the list/Overview. Public data here means available through authorized access,
not anonymous access to the organization.

### Management membership data

Access results include `access.pub`, the public JSON payload for that specific
membership. The frontend exposes a compact **Data (JSON)** box on each access
card, labeled **Data** above the textarea; **Modify** saves it together with
the access level. The card's **Tags** button sits in the tags fieldset legend. Objects and arrays are
accepted; a blank box sends `null` to clear the payload. Invalid JSON is rejected
before the frontend makes a request. The API rejects scalar payloads, including a JSON-encoded string instead of an
object/array. Explicit JSON `null` is stored as JSON null; omitting `pub` preserves
it. An empty object may round-trip as `[]` because the shared repository decodes
objects into associative PHP arrays. Do not use object-versus-array shape alone
as a permission signal.

```json
{
  "org": "11111111-1111-4111-8111-111111111111",
  "principal": "66666666-6666-4666-8666-666666666666",
  "membership": "44444444-4444-4444-8444-444444444444",
  "role": "member",
  "pub": { "permissions": ["publish"], "quota": 10 }
}
```

The shared groups service stores this in `organization_manage_group_meta.pub`,
with `asset` equal to `organization_manage_group_members.id`. The backend resolves
the membership within the authorized org and rejects a stale `membership` UUID.
This prevents one principal's data from being shared between orgs or inherited
after removal and re-addition. No table or column migration is needed.

Role-only requests continue to work and preserve the stored payload. Public-data
updates preserve existing `pri` and `public_role`; neither field is accepted by
this route or included in access results. Membership removal clears its metadata
and tags in the same transaction. Tag definition `data` remains independent.

This JSON is service-defined information. The current
[SSO organization response](https://m7.org/docs/api/sso.user.m7.org/userinfo-orgs.md)
and [SDK acquisition](https://m7.org/docs/sdk/m7-identity/cli/organization-access.md)
transport this membership `pub` and assigned tags with tag definition `data`.
Saving them does not implement a consuming service's permission policy.

For `type: "user"`, `principal` is the user UUID. For `type: "app"`, it is the
OAuth application's public `client_id`. A `delegate` principal must already
exist.

### Add a Management member

```bash
curl -sS https://api.user.m7.org/api/v2/org/manage/add \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "org": "11111111-1111-4111-8111-111111111111",
    "type": "user",
    "principal": "22222222-2222-4222-8222-222222222222",
    "role": "admin"
  }'
```

```json
{
  "status": 1,
  "comment": "OK",
  "data": {
    "access": {
      "id": "44444444-4444-4444-8444-444444444444",
      "principal": "66666666-6666-4666-8666-666666666666",
      "role": "admin",
      "pub": null,
      "tags": []
    },
    "principal": {
      "rid": "22222222-2222-4222-8222-222222222222",
      "name": "alice",
      "type": "user"
    }
  }
}
```

### Management membership scope tags

`search`, `get`, `add`, `set`, and `set_tags` return assigned tags under
`data.access.tags` (under each item's `access.tags` for search). Each tag includes
`id`, `name`, `slug`, `description`, optional JSON `data`, and creation/update
timestamps.

Storage uses `organization_manage_tag_names` and
`organization_manage_tag_junction`. The pool scope is
`organization_management` plus the organization UUID; the assignment asset is
`organization_management_member` plus the Management membership UUID.
The tag pool belongs to one org. Assignments belong to the access entry's
membership UUID, rather than the user or application globally. The same principal
may have different tags in different orgs. Removing a membership clears its
assignments; re-adding that principal creates a new membership with no tags.

`principal` for `set_tags` is the Management principal UUID returned by the
access API, and `membership` is `access.id`. A stale membership UUID is rejected
so a save cannot affect a membership created after removal. The replacement is
atomic; tags from another org or duplicate tag IDs are rejected.

| Route | Required fields | Optional fields |
| --- | --- | --- |
| `/org/manage/tags/search` | `org` | `tag_id`, `name`, `slug`, `limit`, `offset`, `cursor`, `page_number` |
| `/org/manage/tags/insert` | `org`, `name` | `slug`, `description`, `data` |
| `/org/manage/tags/update` | `org`, `tag_id` | `name`, `slug`, `description`, `data`; at least one update field |
| `/org/manage/tags/delete` | `org`, `tag_id` | None; an assigned tag cannot be deleted |

Tag search defaults to `limit: 50` (maximum 100) and offset 0. It returns
`scope`, `tags`, `limit`, `offset`, `has_more`, `next_offset`,
and `next_cursor`. Follow `next_cursor` until `has_more` is false. Slugs are
unique within an org's management tag pool. JSON `data` accepts an object/array
or null; it is tag definition metadata shared by every assigned membership.
Omission on update preserves existing data; null clears it. An empty string
also normalizes to null in the shared tag service; whitespace-only strings,
JSON-encoded strings and other scalars are rejected. The frontend's blank JSON
editor sends null. Empty objects can serialize as
`[]` through associative decoding.

These routes require current organization owner authority. Their M7
API token scopes are `org.manage.set_tags`, `org.manage.tags.search`,
`org.manage.tags.insert`, `org.manage.tags.update`, and `org.manage.tags.delete`,
respectively, with the existing first-party panel exemption and prefix rules.
Tag names preserve dots and case; outer whitespace is trimmed. Slugs are
normalized separately: a name `test.me` can arrive at SSO with slug `testme`.
Neither API User nor SSO rewrites the stored name into that slug.
These exported facts do not grant additional Management authority within API
User. In current Blog source, verified Management `tags[].name` is the
capability/profile identifier (`post.save`, `post.read`, or `preset.writer`),
resolved case-insensitively through Blog's SQL catalogue. Slugs and arbitrary
tag `data` supply no Blog capability grants, while slugs retain generic tag
uses. Nonempty unknown-name selections grant nothing and never trigger role
defaults. Only verified empty tags permit Owner/Admin defaults; Member has no
automatic grant. Missing/malformed facts fail closed, and org grants remain
bounded by actual publication access and independent membership/owner checks.

See [current Blog tag-name resolution](https://m7.org/docs/api/api.user.m7.org/service-capability-discovery.md#blog-organization-tag-names-source-verified)
and the separate proposed registration/version approval contract in that guide.
The proposed selection schema is not Blog's implemented tag input format.

```json
{
  "org": "11111111-1111-4111-8111-111111111111",
  "principal": "66666666-6666-4666-8666-666666666666",
  "membership": "44444444-4444-4444-8444-444444444444",
  "tag_ids": ["55555555-5555-4555-8555-555555555555"]
}
```

The backend lazily installs `organization_manage_tag_names` and
`organization_manage_tag_junction` using the shared tag repository templates.
Deploy API User and User M7 together. The frontend exposes **Access → Members → Tags** on
each membership, with selected chips, the checklist, and add/edit/manage controls
copied from application registration. Tag metadata has an optional Data (JSON)
editor. The access card's separate membership Data box uses group metadata `pub`
as described above. Scope facts are exported through the current SSO/SDK
contract. The standalone catalogue management page was cancelled; use the picker
on an individual access entry. The shared tag-pool proposal was also cancelled.
See [installation and upgrade order](https://m7.org/docs/api/api.user.m7.org/organization-upgrade.md).

## Organization groups

Use `/org/group/*` for ordinary groups such as `Operators` or `Billing`.

| Route | Required fields | Notes |
| --- | --- | --- |
| `/org/group/search` | `org` | Optional `archived` boolean. |
| `/org/group/insert` | `org`, `name` | Creates a group. |
| `/org/group/get` | `org`, `id` | The group must belong to the authorized organization. |
| `/org/group/update` | `org`, `id` | Partially updates a group. |
| `/org/group/delete` | `org`, `id` | Archives or deletes a group. |
| `/org/group/restore` | `org`, `id` | Restores a group. |

```bash
curl -sS https://api.user.m7.org/api/v2/org/group/insert \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "org": "11111111-1111-4111-8111-111111111111",
    "name": "Operators"
  }'
```

## Organization members

The `/org/client/*` path manages organization members. The `client` in the
path is a member record, not an OAuth application.

| Route | Required fields | Optional fields and behavior |
| --- | --- | --- |
| `/org/client/search` | `org` | `archived`, search fields, and optional `group` (group UUID or slug) to filter membership. |
| `/org/client/insert` | `org`, `name` | `user` may link an active, unarchived consumer-user UUID. An unavailable user returns `linked user is unavailable`. |
| `/org/client/get` | `org`, plus `id` or `name` | Returns one member. |
| `/org/client/update` | `org`, `id` | Partial update; `user` uses the same availability check. |
| `/org/client/archive` | `org`, `id` | Reversibly archives a member, then disables every delegated/password and shadow M7 identity using API User's master grant. |
| `/org/client/delete` | `org`, `id` | Permanently deletes an already archived member. M7-owned remote identities must be retired first; external provider accounts and linked consumer users are never deleted. |
| `/org/client/restore` | `org`, `id` | Reactivates every delegated/password and shadow M7 identity, then restores the local member. |
| `/org/client/password` | `org`, `id`, `pass`, `confirm` | Cannot change the password for a member linked to a consumer user. |
| `/org/client/federated-identity` | `org`, `id`, `vendor`, `rid` | `handle` is optional. Binds a federated identity to the organization member. |

Permanent deletion is intentionally a two-step lifecycle. Call
`/org/client/archive` first, then `/org/client/delete`. The permanent operation
fails closed if remote M7 credential cleanup cannot be confirmed, leaving the
archived member and all local rows available for a safe retry. It removes
group memberships, member emails, the member profile, identity bindings, and
the member row in that order.

Archive and restore never change an external federated-provider account or a
linked global consumer identity. The external provider binding stays local so
the member can be restored. ID.M7 status transitions include a lifecycle
comment and use `disabled`/`active`; permanent remote archive is reserved for
the irreversible delete operation.

### Create an organization member

```bash
curl -sS https://api.user.m7.org/api/v2/org/client/insert \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "org": "11111111-1111-4111-8111-111111111111",
    "name": "alice"
  }'
```

The create response returns `comment: "OK"` and the new member record in
`data`.

## Member group membership

Use `/org/client/group/*` to manage the relationship between an organization
member and an ordinary group.

| Route | Required fields | Notes |
| --- | --- | --- |
| `/org/client/group/add` | `org`, `id`, `group` | `id` is the member ID; `group` is the group ID. The membership role is always `member`. Duplicate addition returns `client is already a member of this group`. |
| `/org/client/group/remove` | `org`, `id`, `group` | Removes a member from a group. |
| `/org/client/group/get` | `org`, `group`, plus `id` or `name` | Looks up a relationship by group and member. |
| `/org/client/group/set` | `org`, `group`, plus `client` or `id` | Updates the existing relationship. `id` is an alias for the member ID when `client` is omitted. |
| `/org/client/group/search` | `org`, plus group `id` or `name` | Lists members in one group. |
| `/org/client/group/all` | `org`, `id` | Returns all organization groups with membership information for one member. |

### Add a member to a group

```bash
curl -sS https://api.user.m7.org/api/v2/org/client/group/add \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "org": "11111111-1111-4111-8111-111111111111",
    "id": "77777777-7777-4777-8777-777777777777",
    "group": "88888888-8888-4888-8888-888888888888"
  }'
```

```json
{
  "status": 1,
  "comment": "ADDED",
  "data": {
    "group": "88888888-8888-4888-8888-888888888888",
    "client": "77777777-7777-4777-8777-777777777777",
    "role": "member"
  }
}
```

## User M7 access experience

Owners retain all org controls. Admin cards enter the tenant workspace, with
owner controls and app/key inventory hidden. Admin gear and the workspace's
Properties/Permissions action open the shared read-only modal. Members open that
modal from either their org card or its gear instead of navigating to management.
Properties shows Org Data; Permissions shows the caller's access level,
membership ID, scopes and tag data, and membership `pub`. Active Tags controls
visibility and prevents hidden inventory requests; direct API authorization
always uses the live stored role. Late responses and changed sessions cannot
populate another modal context.

For cross-service pickup and storage prerequisites, see
[organization upgrade](https://m7.org/docs/api/api.user.m7.org/organization-upgrade.md).
