We provide two of methods for fetching tenants:
- Get tenants to fetch more than one tenant at a time.
- Get tenant by ID
For all of these queries you need the following permissions:
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);
}
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);
}
query tenants($first: Int, $after: String, $last: Int, $before: String) {
tenants(first: $first, after: $after, last: $last, before: $before) {
edges {
cursor
node {
id
name
externalId
url
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
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);
}
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);
}
query tenant($tenantId: ID!) {
tenant(tenantId: $tenantId) {
id
externalId
name
url
}
}