An Organization is a top-level resource in WorkOS. Each Connection, Directory, and Audit Trail Event belongs to an Organization. An Organization will usually represent one of your customers. There is no limit to the number of organizations you can create in WorkOS.
const organization = { object: 'organization', id: 'org_01EHZNVPK3SFK441A1RGBFSHRT', name: 'Foo Corp', createdAt: '2021-06-25T19:07:33.155Z', updatedAt: '2021-06-25T19:07:33.155Z', domains: [ { id: 'org_domain_01EHZNVPK2QXHMVWCEDQEKY69A', object: 'organization_domain', domain: 'foo-corp.com', }, ], stripeCustomerId: 'cus_R9qWAGMQ6nGE7V', externalId: '2fe01467-f7ea-4dd2-8b79-c2b4f56d0191', };
interface OrganizationGet the details of an existing organization.
import { WorkOS } from '@workos-inc/node'; const workos = new WorkOS('sk_example_123456789'); const organization = await workos.organizations.getOrganization( 'org_01EHZNVPK3SFK441A1RGBFSHRT', );
Get the details of an existing organization by an external identifier.
import { WorkOS } from '@workos-inc/node'; const workos = new WorkOS('sk_example_123456789'); const organization = await workos.organizations.getOrganizationByExternalId( '2fe01467-f7ea-4dd2-8b79-c2b4f56d0191', );
Get a list of all of your existing organizations matching the criteria specified.
import { WorkOS } from '@workos-inc/node'; const workos = new WorkOS('sk_example_123456789'); const organizations = await workos.organizations.listOrganizations({ domains: ['foo-corp.com'], }); console.log(organizations.data);
organizations .listOrganizations()Parameters objectReturns objectCreates a new organization in the current environment.
You can include one or more domains to associate with the organization, but you should verify the ownership of every domain before setting its state to verified.
import { WorkOS } from '@workos-inc/node'; const workos = new WorkOS('sk_example_123456789'); const organization = await workos.organizations.createOrganization({ name: 'Foo Corp', domainData: [ { domain: 'foo-corp.com', state: 'pending', }, ], externalId: '2fe01467-f7ea-4dd2-8b79-c2b4f56d0191', metadata: { tier: 'diamond', }, });
Updates an organization in the current environment.
You can include one or more domains to associate with the organization, but you should verify the ownership of every domain before setting its state to verified.
import { WorkOS } from '@workos-inc/node'; const workos = new WorkOS('sk_example_123456789'); const organization = await workos.organizations.updateOrganization({ organization: 'org_01EHZNVPK3SFK441A1RGBFSHRT', name: 'Foo Corp', domainData: [ { domain: 'foo-corp.com', state: 'verified', }, ], externalId: '2fe01467-f7ea-4dd2-8b79-c2b4f56d0191', metadata: { tier: 'diamond', }, stripeCustomerId: 'cus_R9qWAGMQ6nGE7V', });
Permanently deletes an organization in the current environment. It cannot be undone.
import { WorkOS } from '@workos-inc/node'; const workos = new WorkOS('sk_example_123456789'); await workos.organizations.deleteOrganization('org_01EHZNVPK3SFK441A1RGBFSHRT');
organizations .deleteOrganization()Parameters