Skip to main content
The Organizations API allows you to create, retrieve, update, and delete organizations, as well as manage organization-specific resources like roles, feature flags, and API keys.

Initialize

import { WorkOS } from '@workos-inc/node';

const workos = new WorkOS('sk_example_123456789');

Methods

listOrganizations

Retrieve a list of organizations.
const organizations = await workos.organizations.listOrganizations({
  domains: ['example.com'],
  limit: 10,
});

for await (const organization of organizations) {
  console.log(organization.id, organization.name);
}
options
ListOrganizationsOptions
Options for filtering and paginating organizations.
organizations
AutoPaginatable<Organization>
An auto-paginatable list of organizations.

createOrganization

Create a new organization.
const organization = await workos.organizations.createOrganization({
  name: 'Acme Corporation',
  domainData: [
    { domain: 'acme.com', state: 'verified' },
  ],
  externalId: 'external_123',
  metadata: { industry: 'technology' },
});
payload
CreateOrganizationOptions
required
The organization data.
requestOptions
CreateOrganizationRequestOptions
organization
Organization
The created organization object.

getOrganization

Retrieve an organization by ID.
const organization = await workos.organizations.getOrganization('org_123');
id
string
required
The unique identifier of the organization.
organization
Organization
The organization object.

getOrganizationByExternalId

Retrieve an organization by external ID.
const organization = await workos.organizations.getOrganizationByExternalId('external_123');
externalId
string
required
The external identifier of the organization.
organization
Organization
The organization object.

updateOrganization

Update an existing organization.
const organization = await workos.organizations.updateOrganization({
  organization: 'org_123',
  name: 'Acme Corp (Updated)',
  metadata: { industry: 'fintech' },
});
options
UpdateOrganizationOptions
required
organization
Organization
The updated organization object.

deleteOrganization

Delete an organization.
await workos.organizations.deleteOrganization('org_123');
id
string
required
The unique identifier of the organization to delete.

listOrganizationRoles

Retrieve all roles for an organization.
const roleList = await workos.organizations.listOrganizationRoles({
  organizationId: 'org_123',
});

console.log(roleList.data);
options
ListOrganizationRolesOptions
required
roleList
RoleList

listOrganizationFeatureFlags

Retrieve feature flags for an organization.
const featureFlags = await workos.organizations.listOrganizationFeatureFlags({
  organizationId: 'org_123',
  limit: 20,
});

for await (const flag of featureFlags) {
  console.log(flag.key, flag.enabled);
}
options
ListOrganizationFeatureFlagsOptions
required
featureFlags
AutoPaginatable<FeatureFlag>
An auto-paginatable list of feature flags.

listOrganizationApiKeys

Retrieve API keys for an organization.
const apiKeys = await workos.organizations.listOrganizationApiKeys({
  organizationId: 'org_123',
  limit: 10,
});

for await (const apiKey of apiKeys) {
  console.log(apiKey.id, apiKey.name);
}
options
ListOrganizationApiKeysOptions
required
apiKeys
AutoPaginatable<ApiKey>
An auto-paginatable list of API keys.

createOrganizationApiKey

Create an API key for an organization.
const apiKey = await workos.organizations.createOrganizationApiKey({
  organizationId: 'org_123',
  name: 'Production API Key',
});

console.log(apiKey.secret); // Only returned on creation
options
CreateOrganizationApiKeyOptions
required
requestOptions
CreateOrganizationApiKeyRequestOptions
createdApiKey
CreatedApiKey
The created API key object including the secret (only returned once).

Build docs developers (and LLMs) love