Add multi-org child organization tools#14
Conversation
Tested against a live multi-org (provider) tenant — child-org discovery returns 0 orgsThanks for this PR! The What's failing
What the docs say
Suggested fixUse the full-object endpoint first, keep the documented async def _get_child_organizations(client: SecureAccessClient) -> list[dict[str, Any]]:
# /admin/v2/tenants returns full objects (id + name). The documented
# /admin/v2/tenants/lists returns a bare list of org IDs (no names);
# legacy /tenants/list now 404s. Keep all three as narrow 404 fallbacks.
last_exc: SecureAccessAPIError | None = None
for endpoint in ("tenants", "tenants/list", "tenants/lists"):
try:
data = await client.get(ADMIN_SCOPE, endpoint)
except SecureAccessAPIError as exc:
if exc.status_code != 404:
raise
last_exc = exc
continue
organizations = _extract_child_organizations(data)
if organizations:
return organizations
if last_exc is not None:
raise last_exc
return []# in _extract_child_organizations(...), inside the `for item in data:` loop:
for item in data:
if isinstance(item, dict):
org_id = _first_scalar(item, ("organizationId", "organization_id", "orgId", "org_id", "id"))
org_name = _first_scalar(
item, ("organizationName", "organization_name", "orgName", "org_name", "name", "label")
)
elif isinstance(item, (str, int)) and not isinstance(item, bool):
# The documented /admin/v2/tenants/lists endpoint returns a bare
# list of tenant organization IDs without names.
org_id = str(item).strip()
org_name = None
else:
continue
if not org_id or org_id in seen:
continue
seen.add(org_id)
organizations.append({"organizationId": org_id, "organizationName": org_name})
|
Live
|
… id+name The previous /admin/v2/tenants/list endpoint returns 404 and the bare /tenants/lists returns ID-only arrays, yielding count: 0. Query the documented /admin/v2/tenants/lists with optionalFields=[organizationName,includeUmbrellaOrgs] so every child org returns organizationId + organizationName, and harden the parser to accept both object and bare-ID list responses.
Summary
Testing