Organizations
ulex Organizations API: create, read, update and delete customer organizations; verified email domains with TXT challenges; organization memberships with owner/admin/member/guest roles; and organization-scoped groups.
An organization is the unit a customer of your app signs up for. It owns domains, groups, memberships, and (optionally) a connection and a directory.
Users are tenant-global. A user with dana@acme.example exists once; she can be a member of three organizations. Scoping to a customer happens through organization_membership, exactly as in WorkOS and Entra External ID. Do not try to scope users by organisation — create one user and three memberships.
Required scopes: read:organizations, write:organizations. Groups additionally need read:groups / write:groups.
#Object
{
"id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"object": "organization",
"name": "Acme Corp",
"slug": "acme",
"logo_url": "https://cdn.example.com/acme.png",
"directory_id": "dir_01M3PSVBF8038RK2MW2N263Q2B",
"connection_id": "con_01M3PSVAG0QFJG99R0M5DXSR5A",
"sso_only": true,
"allow_profiles_outside_organization": false,
"default_connection_id": "con_01M3PSVAG0QFJG99R0M5DXSR5A",
"metadata": { "plan_tier": "enterprise" },
"created_at": "2026-09-29T14:42:06.000Z",
"updated_at": "2026-09-29T14:42:06.000Z"
}| Field | Type | Notes |
|---|---|---|
id | org_… | prefixed ULID, lexicographically sortable by creation time |
slug | string | ^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$, 2–63, unique per tenant, immutable |
directory_id | dir_… | null | set when the org is backed by a synced directory |
connection_id | con_… | null | the IdP this org's members authenticate through |
sso_only | boolean | when true, confines members to this org's connection_id or default_connection_id |
allow_profiles_outside_organization | boolean | when false, restricts joining to users whose email matches a verified org domain |
default_connection_id | con_… | null | the connection used when the caller does not name one |
metadata | Record<string, string|number|boolean|null> | arbitrary, never indexed, never used for auth decisions |
#SSO and profile isolation enforcement
sso_only and allow_profiles_outside_organization are enforced boundaries:
sso_only: Enforced at session creation. Whentrue, direct password sign-in is refused with403 access_denied(code: access_denied), and users must authenticate through an enterprise SSO connection bound to the organization (connection_idordefault_connection_id).- Most-restrictive rule: If a user belongs to multiple organizations and at least one is
sso_only: true, the most restrictive rule applies. The user cannot use password sign-in, and the connection used must be permitted by everysso_onlyorganization they belong to.
- Most-restrictive rule: If a user belongs to multiple organizations and at least one is
allow_profiles_outside_organization: Enforced when a user joins or provisions into an organization (JIT provisioning, SCIM provisioning, portal invitations, and adding members). Whenfalse(default), the user's email domain must match an active domain on the organization inverifiedstate (domain.state === 'verified'). Otherwise, joining is rejected with403 access_denied. Whentrue, any email domain is permitted.
#Create
curl -sS -X POST "$BASE/organizations" \
-H "Authorization: Bearer $ULEX_API_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: 1f4c9e2a-3b7d-4a1e-9c58-0f2a6b3d81cc" \
-d '{"name":"Acme Corp","slug":"acme","sso_only":true,"metadata":{"plan_tier":"enterprise"}}'{
"id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"object": "organization",
"name": "Acme Corp",
"slug": "acme",
"logo_url": null,
"directory_id": null,
"connection_id": null,
"sso_only": true,
"allow_profiles_outside_organization": false,
"default_connection_id": null,
"metadata": { "plan_tier": "enterprise" },
"created_at": "2026-09-29T14:42:06.000Z",
"updated_at": "2026-09-29T14:42:06.000Z"
}Errors: 409 resource_exists (slug taken), 400 validation_failed (bad slug), 403 insufficient_scope.
#List
curl -sS "$BASE/organizations?limit=20&order=asc" -H "Authorization: Bearer $ULEX_API_KEY"{
"object": "list",
"data": [
{ "id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C", "object": "organization", "name": "Acme Corp", "slug": "acme", "sso_only": true },
{ "id": "org_01M3PSVT404FMFWPN6QAMM2R4P", "object": "organization", "name": "Globex", "slug": "globex", "sso_only": false }
],
"first_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"last_id": "org_01M3PSVT404FMFWPN6QAMM2R4P",
"has_more": false,
"next_cursor": null
}Filters: limit, starting_after, ending_before, order, connection_id, domain, search (name or slug prefix).
#Read, update, delete
curl -sS "$BASE/organizations/org_01M3PSV8HGTKQFCAYF9GDWGN3C" -H "Authorization: Bearer $ULEX_API_KEY"
curl -sS -X PATCH "$BASE/organizations/org_01M3PSV8HGTKQFCAYF9GDWGN3C" \
-H "Authorization: Bearer $ULEX_API_KEY" -H "Content-Type: application/json" \
-d '{"connection_id":"con_01M3PSVAG0QFJG99R0M5DXSR5A","sso_only":true}'
curl -sS -X DELETE "$BASE/organizations/org_01M3PSV8HGTKQFCAYF9GDWGN3C" -H "Authorization: Bearer $ULEX_API_KEY"{ "id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C", "object": "organization", "deleted": true, "deleted_at": "2026-09-29T16:00:00.000Z", "restore_window_days": 30 }PATCH accepts exactly the mutable fields: name, logo_url, sso_only, allow_profiles_outside_organization, connection_id, directory_id, metadata. An empty body is 400 validation_failed with hint: "Provide at least one field to update". slug and id are 409 immutable_field.
DELETE is a soft delete. The organization is hidden from all reads, its memberships are revoked, its active sessions are terminated, and organization.deleted is written to the audit log. It is restorable for 30 days.
#Domains
Domains attach an email domain to an organization, which is what routes users of that domain to the organization's SSO connection. Full REST surface plus MCP tools; both call the same implementation, so they cannot disagree about what adding or verifying proved.
DOM=$(curl -sS -X POST "$BASE/organizations/$ORG_ID/domains" -H "$AUTH" -H "$JSON" \
-d '{"domain":"acme.example","verification_strategy":"dns"}')
DOM_ID=$(jq -r .domain.id <<<"$DOM")
curl -sS -X POST "$BASE/organizations/$ORG_ID/domains/$DOM_ID/verify" -H "$AUTH" -H "$JSON" -d '{}'
curl -sS "$BASE/organizations/$ORG_ID/domains" -H "$AUTH"
curl -sS -X DELETE "$BASE/organizations/$ORG_ID/domains/$DOM_ID" -H "$AUTH"POST /organizations/{id}/domains accepts domain (required), verification_strategy (dns, default) and auto_verify (requires allow_mocks: true or local mode). It answers 201 with the domain, the dns_record TXT challenge, and the state — and answers 200 with already_exists: true when the domain is already attached, so a retry after a timeout is safe. Adding to an unknown organization is 404.
{
"domain": {
"id": "dom_01M3PSVCEGK9H35GZJK25HN08D",
"object": "domain",
"organization_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"name": "acme.example",
"state": "pending",
"verification_strategy": "dns",
"verification_token": "ulex-verification=…",
"verified_at": null
},
"dns_record": { "type": "TXT", "name": "_ulex-challenge.acme.example", "value": "ulex-verification=…", "ttl": 3600 },
"state": "pending"
}POST /organizations/{id}/domains/{domainId}/verify accepts an optional force flag and answers 200 with the domain and its state. Verifying an already-verified domain is a no-op reporting already_verified: true. A domain id from another organization — or another tenant — answers the same 404 as one that does not exist.
DELETE /organizations/{id}/domains/{domainId} answers 204. Deleting twice is 404 the second time. Removing the last verified domain of an sso_only: true organization is refused with 409 sso_domain_required: with joining closed to unverified addresses, deleting it bricks every future login, so verify a replacement first or set sso_only to false.
Use the tools for the same operations:
{ "name": "ulex_add_domain", "arguments": { "organization_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C", "domain": "acme.example" } }
{ "name": "ulex_verify_domain", "arguments": { "domain_id": "dom_01M3PSVCEGK9H35GZJK25HN08D" } }
{ "name": "ulex_list_domains", "arguments": { "organization_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C" } }
{ "name": "ulex_remove_domain", "arguments": { "domain_id": "dom_01M3PSVCEGK9H35GZJK25HN08D", "confirm": true } }#Object
{
"id": "dom_01M3PSVCEGK9H35GZJK25HN08D",
"object": "domain",
"organization_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"name": "acme.example",
"state": "verified",
"verification_strategy": "dns",
"verified_at": "2026-09-29T14:42:10.000Z"
}state is pending, verifying, verified or failed. Reads (the verify response, the list) never carry verification_token: it is returned once, in the add response, alongside the dns_record TXT challenge. A list that returned it would hand every reader the value needed to verify a domain they do not control.
#Verification
POST /organizations/{id}/domains returns a verification_token and the dns_record TXT record to publish. POST .../domains/{domainId}/verify marks the domain verified. Every add, verify, and remove is recorded in the audit log as domain.created, domain.verified, and domain.deleted.
When tenant.allow_mocks is true (or in local mode), verification resolves on the first call — there is no DNS lookup, by design, so an agent never has to touch a DNS provider. Otherwise, the TXT record must exist and must have propagated.
state moves to failed on a failed verification. Removing a domain detaches it and stops routing its users; see the 409 rule above for the one case where removal is refused.
#Memberships
#Object
{
"id": "mem_01M3PSVDDRC5YN00BRZ8E7CNMT",
"object": "organization_membership",
"organization_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"user_id": "usr_01M3PSV9GRT8GQGEG686AR1W9S",
"role": "owner",
"group_ids": ["grp_01M3PSVED0M9RJTYH5AC72C253"],
"created_at": "2026-09-29T14:42:11.000Z",
"updated_at": "2026-09-29T14:42:11.000Z"
}role ∈ owner | admin | member | guest. group_ids are groups within the same organization; a cross-organization group id is 400 validation_failed with param: "group_ids".
#Create or update
curl -sS -X POST "$BASE/organizations/org_01M3PSV8HGTKQFCAYF9GDWGN3C/members" \
-H "Authorization: Bearer $ULEX_API_KEY" -H "Content-Type: application/json" \
-d '{"user_id":"usr_01M3PSV9GRT8GQGEG686AR1W9S","role":"owner","group_ids":["grp_01M3PSVED0M9RJTYH5AC72C253"]}'This is an upsert. Calling it twice for the same (organization_id, user_id) updates the existing membership rather than creating a second one, which makes it safe to run in a loop over a directory sync.
PUT /organizations/{id}/members/{userId} is the same operation addressed by user id, and additionally replaces group_ids wholesale:
curl -sS -X PUT "$BASE/organizations/org_01M3PSV8HGTKQFCAYF9GDWGN3C/members/usr_01M3PSWBPGS08FWV4NV7P9VNFN" \
-H "Authorization: Bearer $ULEX_API_KEY" -H "Content-Type: application/json" \
-d '{"role":"admin","group_ids":["grp_01M3PSVED0M9RJTYH5AC72C253"]}'#Join policy
allow_profiles_outside_organization controls whether users with email addresses outside verified organization domains can join the organization:
allow_profiles_outside_organization | Enforced behaviour |
|---|---|
false (default) | the email's domain must match a verified domain (state: verified) on the organization; non-matching emails are refused with 403 access_denied |
true | any email may join |
#List and remove
curl -sS "$BASE/organizations/org_01M3PSV8HGTKQFCAYF9GDWGN3C/members?limit=100" -H "Authorization: Bearer $ULEX_API_KEY"
curl -sS -X DELETE "$BASE/organizations/org_01M3PSV8HGTKQFCAYF9GDWGN3C/members/usr_01M3PSWBPGS08FWV4NV7P9VNFN" \
-H "Authorization: Bearer $ULEX_API_KEY"Removing a membership revokes that user's sessions in this organization only. Their tokens in other organizations stay valid. Removing the last owner is rejected with 409 invalid_state_transition.
Filters on the members list: role, group_id, search (email prefix), limit, starting_after.
#Groups
Groups are addressed at the top level but always belong to one organization.
curl -sS -X POST "$BASE/organizations/org_01M3PSV8HGTKQFCAYF9GDWGN3C/groups" \
-H "Authorization: Bearer $ULEX_API_KEY" -H "Content-Type: application/json" \
-d '{"name":"Engineering","slug":"engineering","description":"Eng staff","source":"rule"}'{
"id": "grp_01M3PSVED0M9RJTYH5AC72C253",
"object": "group",
"organization_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"name": "Engineering",
"slug": "engineering",
"description": "Eng staff",
"scim_id": null,
"source": "rule",
"created_at": "2026-09-29T14:42:12.000Z",
"updated_at": "2026-09-29T14:42:12.000Z"
}| Field | Notes |
|---|---|
slug | ^[a-zA-Z0-9._:-]+$, 1–120, unique within the organization, emitted in the groups claim |
scim_id | the opaque id on the directory side, set automatically on SCIM sync |
source | manual (you created it), scim (came from /scim/v2/Groups), saml (created from an assertion group), rule (matched by email or email domain) |
#Replace group membership
curl -sS -X PUT "$BASE/groups/grp_01M3PSVED0M9RJTYH5AC72C253/members" \
-H "Authorization: Bearer $ULEX_API_KEY" -H "Content-Type: application/json" \
-d '{"user_ids":["usr_01M3PSV9GRT8GQGEG686AR1W9S","usr_01M3PSWBPGS08FWV4NV7P9VNFN"]}'{
"id": "grp_01M3PSVED0M9RJTYH5AC72C253",
"object": "group",
"organization_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"name": "Engineering",
"slug": "engineering",
"member_count": 2,
"members": [
{ "user_id": "usr_01M3PSV9GRT8GQGEG686AR1W9S", "email": "dana@acme.example" },
{ "user_id": "usr_01M3PSWBPGS08FWV4NV7P9VNFN", "email": "pat@acme.example" }
]
}PUT is a replace, not an append. Omit a user and they are removed. This is the right semantic for directory sync; if you want append, read then write.
#Patch and delete
curl -sS -X PATCH "$BASE/groups/grp_01M3PSVED0M9RJTYH5AC72C253" \
-H "Authorization: Bearer $ULEX_API_KEY" -H "Content-Type: application/json" \
-d '{"name":"Engineering & Platform","description":"Renamed 2026-09"}'
curl -sS -X DELETE "$BASE/groups/grp_01M3PSVED0M9RJTYH5AC72C253" -H "Authorization: Bearer $ULEX_API_KEY"{ "id": "grp_01M3PSVED0M9RJTYH5AC72C253", "object": "group", "deleted": true }slug and organization_id are immutable. Deleting a group removes it from every membership's group_ids; users are not deleted.
#Multi-tenant onboarding in one shell
set -euo pipefail
BASE="https://ulexid.com/api/v1"
AUTH="Authorization: Bearer $ULEX_API_KEY"
JSON="Content-Type: application/json"
K="onboard-acme.example"
ORG=$(curl -sS -X POST "$BASE/organizations" -H "$AUTH" -H "$JSON" -H "Idempotency-Key: $K-org" \
-d '{"name":"Acme Corp","slug":"acme","sso_only":true}')
ORG_ID=$(jq -r .id <<<"$ORG")
DOM=$(curl -sS -X POST "$BASE/organizations/$ORG_ID/domains" -H "$AUTH" -H "$JSON" \
-d '{"domain":"acme.example","verification_strategy":"dns"}')
curl -sS -X POST "$BASE/organizations/$ORG_ID/domains/$(jq -r .domain.id <<<"$DOM")/verify" -H "$AUTH" | jq -r '.state'
GRP=$(curl -sS -X POST "$BASE/organizations/$ORG_ID/groups" -H "$AUTH" -H "$JSON" \
-d '{"name":"All Staff","slug":"all-staff","source":"rule"}')
GRP_ID=$(jq -r .id <<<"$GRP")
for email in dana@acme.example pat@acme.example; do
USR=$(curl -sS -X POST "$BASE/users" -H "$AUTH" -H "$JSON" -H "Idempotency-Key: $K-user-$email" \
-d "{\"email\":\"$email\",\"email_verified\":true}")
USR_ID=$(jq -r .id <<<"$USR")
ROLE=member; [ "$email" = "dana@acme.example" ] && ROLE=owner
curl -sS -X POST "$BASE/organizations/$ORG_ID/members" -H "$AUTH" -H "$JSON" \
-d "{\"user_id\":\"$USR_ID\",\"role\":\"$ROLE\",\"group_ids\":[\"$GRP_ID\"]}" | jq -r '"\(.id) \(.role)"'
doneverified
mem_01M3PSVDDRC5YN00BRZ8E7CNMT owner
mem_01M3PSW0YRNEQQAP9T1JP9FC2Y member#MCP equivalents
ulex_create_organization, ulex_list_organizations, ulex_get_organization, ulex_update_organization, ulex_delete_organization, ulex_add_domain, ulex_verify_domain, ulex_list_domains, ulex_remove_domain, ulex_add_organization_member, ulex_remove_organization_member, ulex_list_organization_members, ulex_create_group, ulex_list_groups, ulex_set_group_members.
See Organizations patterns and the MCP tools reference.