Set up a directory, install the SDK, and integrate Directory Sync.
Set up Directory Sync to synchronize user and group data from your customers’ identity providers.
This guide covers:
Make sure you have:
The WorkOS Directory Sync API exclusively uses read-only operations. We never mutate end-user directories.
Create an organization in the WorkOS Dashboard, then create a new connection to the organization’s directory. Start by creating one for development in your sandbox environment.
Select the directory provider to test for provider-specific instructions:
Configure a directory connection to Okta.
Configure an Entra ID directory connection.
Configure a Google Workspace directory connection.
Choose from dozens of other directory providers.
You can view and copy the unique identifier for the directory connection on the directory page, once it has been set up. The id takes the form directory_*.
Integrate the Directory Sync API into your app to fetch directory resources programmatically.
WorkOS offers native SDKs in several popular programming languages. Choose a language below to see instructions in your application’s language.
Don't see an SDK you need? Contact us to request an SDK!
Install the SDK using the command below.
npm install @workos-inc/node
Provide the API key and, in some cases, the client ID. Store these values as managed secrets and pass them to the SDKs either as environment variables or directly in your app’s configuration.
WORKOS_API_KEY='sk_example_123456789' WORKOS_CLIENT_ID='client_123456789'
The code examples use your staging API keys when signed in.
Get the details of an existing directory user.
Example use case: pre-populate user attributes for new user accounts.
Get directory users for a given directory or directory group.
Example use case: Build an onboarding experience that allows an admin to select who to invite and create accounts for.
const { WorkOS } = require('@workos-inc/node'); const workos = new WorkOS(process.env.WORKOS_API_KEY); // Fetch all Directory Users in a Directory const usersFromDirectory = await workos.directorySync.listUsers({ directory: 'directory_123', }); // Fetch all Directory Users in a Directory Group const usersByGroup = await workos.directorySync.listUsers({ group: 'directory_group_123', });
Use the optional limit, before, and after parameters to paginate through results. See the API Reference for details.
Get the details of an existing directory group.
Example use case: Pre-populate team attributes for new organizations.
Get directory groups for a given directory or directory user.
Example use case: Build an onboarding experience that allows an admin to select which groups of employees to invite and create accounts for.
const { WorkOS } = require('@workos-inc/node'); const workos = new WorkOS(process.env.WORKOS_API_KEY); // Fetch all Directory Groups in a Directory const groupsFromDirectory = await workos.directorySync.listGroups({ // The ID of the Directory to fetch Directory Groups for directory: 'directory_123', }); // Fetch all Directory Groups for a Directory User const groupsByUser = await workos.directorySync.listGroups({ // The ID of the Directory User to fetch Directory Groups for user: 'directory_user_123', });
Use the optional limit, before, and after parameters to paginate through results. See the API Reference for details.
Actions performed in a WorkOS environment are represented by events. These can occur as a result of user-related actions, manually via the WorkOS dashboard, or via API calls. To keep your app in sync with the latest directory data, follow the corresponding guides: