> ## Documentation Index
> Fetch the complete documentation index at: https://namespace.so/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# List Tenants

> List every tenant your platform owns, and find one by its tenant ID or your own customer ID.

Your platform can list every tenant it owns, for example to reconcile them with the customers in your database.
Listing also finds a single tenant, because there is no call that fetches one tenant by ID.

Listing tenants requires a [partner client](/docs/platform/tenants/clients#partner-client). The examples start from `partnerClient`.

## List tenants

`ListTenants` returns tenants in pages. Set `limit` to choose how many tenants a page holds.
A single call returns the first page:

<CodeGroup>
  ```typescript TypeScript theme={null}
  const { tenants } = await partnerClient.tenants.listTenants({ limit: 100 });

  for (const tenant of tenants) {
    console.log(tenant.id, tenant.externalAccountId, tenant.visibleName);
  }
  ```

  ```go Go theme={null}
  resp, err := partnerClient.Tenants.ListTenants(ctx, &iamv1beta.ListTenantsRequest{Limit: 100})
  if err != nil {
  	log.Fatal(err)
  }

  for _, tenant := range resp.Tenants {
  	fmt.Println(tenant.Id, tenant.ExternalAccountId, tenant.VisibleName)
  }
  ```
</CodeGroup>

```text Output theme={null}
tenant_lqrj7qre0ts32 customer-1 Customer 1
tenant_kmtjjrchufgg4 customer-2 Customer 2
tenant_d0s4f2p8ho9ne customer-3 Customer 3
```

## List all tenants

When you have more tenants than one page holds, use the `cursor` from each response to fetch the next page.
Keep requesting pages until the cursor comes back empty.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import type { Tenant } from "@namespacelabs/sdk/proto/namespace/cloud/iam/v1beta/tenants_pb";

  async function listAllTenants(): Promise<Tenant[]> {
    const tenants: Tenant[] = [];
    let cursor = "";

    do {
      const page = await partnerClient.tenants.listTenants({ limit: 100, cursor });
      tenants.push(...page.tenants);
      cursor = page.cursor;
    } while (cursor);

    return tenants;
  }

  for (const tenant of await listAllTenants()) {
    console.log(tenant.id, tenant.externalAccountId, tenant.visibleName);
  }
  ```

  ```go Go theme={null}
  func listAllTenants(ctx context.Context, partnerClient iam.Client) ([]*iamv1beta.Tenant, error) {
  	var tenants []*iamv1beta.Tenant
  	cursor := ""

  	for {
  		page, err := partnerClient.Tenants.ListTenants(ctx, &iamv1beta.ListTenantsRequest{
  			Limit:  100,
  			Cursor: cursor,
  		})
  		if err != nil {
  			return nil, err
  		}

  		tenants = append(tenants, page.Tenants...)
  		if page.Cursor == "" {
  			return tenants, nil
  		}
  		cursor = page.Cursor
  	}
  }
  ```
</CodeGroup>

```text Output theme={null}
tenant_lqrj7qre0ts32 customer-1 Customer 1
tenant_kmtjjrchufgg4 customer-2 Customer 2
tenant_d0s4f2p8ho9ne customer-3 Customer 3
```

## Next steps

<Columns cols={2}>
  <Card title="Update tenants" icon="pencil" href="/docs/platform/tenants/update">
    Rename a tenant and change its labels.
  </Card>

  <Card title="Delete tenants" icon="trash-2" href="/docs/platform/tenants/delete">
    Remove a tenant when a customer leaves.
  </Card>
</Columns>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.