We provide two of methods for fetching tenants:

  1. Get tenants to fetch more than one tenant at a time.
  2. Get tenant by ID

For all of these queries you need the following permissions:

  • tenant:read

Get tenants

Our API allows you to fetch teanants as a collection using getTenants in our SDKs or the tenants query in GraphQL. In both cases this endpoint supports Pagination.

import { PlainClient } from '@team-plain/typescript-sdk';

const client = new PlainClient({ apiKey: 'plainApiKey_xxx' });

const res = await client.getTenants({
  first: 25,
});

if (res.error) {
  console.error(res.error);
} else {
  console.log(res.data);
}

Get tenant by ID

If you know the tenant’s ID in Plain you can use this method to fetch the tenant. Generally speaking it’s preferable to use upsert when you have the full details of the tenant.

import { PlainClient } from '@team-plain/typescript-sdk';

const client = new PlainClient({ apiKey: 'plainApiKey_xxx' });

const res = await client.getTenantById({
  tenantId: 'te_123',
});

if (res.error) {
  console.error(res.error);
} else {
  console.log(res.data);
}