When upserting a tenant you need to specify an externalId which matches the id of the tenant in your own backend.

For example if your product is structured in teams, then when creating a tenant for a team you’d use the team’s id as the externalId.

To upsert a tenant you need the following permissions:

  • tenant:read
  • tenant:create
import { PlainClient } from '@team-plain/typescript-sdk';

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

const res = await client.upsertTenant({
  identifier: {
    externalId: 'team_123',
  },
  externalId: 'team_123',
  name: 'Acme',

  // URL is optional and can be null
  url: {
    value: 'acme.com',
  },
});

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