<!-- llms.txt: https://workos.com/llms.txt -->

# Directory Sync

Read the directory connections of the organization the token was issued for, along with their synced users and groups.

## Get a directory connection

Return a Directory Sync connection by ID within the token's organization.

:::code-group

```graphql language="graphql" title="Query" tab="1"
query DirectoryConnection($id: ID!) {
  directoryConnection(id: $id) {
    createdAt
    externalKey
    id
    name
    organizationId
    state
    type
    updatedAt
  }
}
```

```json language="json" title="Response" tab="2"
{
  "data": {
    "directoryConnection": {
      "createdAt": "2024-01-01T00:00:00.000Z",
      "externalKey": "externalKey_example",
      "id": "id_01EHWNCE74X7JSDV0X3SZ3KJNY",
      "name": "name_example",
      "organizationId": "organizationId_01EHWNCE74X7JSDV0X3SZ3KJNY",
      "state": "state_example",
      "type": "type_example",
      "updatedAt": "2024-01-01T00:00:00.000Z"
    }
  }
}
```

:::

## List directory connections

List the Directory Sync connections for the token's organization.

:::code-group

```graphql language="graphql" title="Query" tab="1"
query DirectoryConnections($after: String, $before: String, $limit: Int, $order: PaginationOrder, $search: String) {
  directoryConnections(after: $after, before: $before, limit: $limit, order: $order, search: $search) {
    data {
      createdAt
      externalKey
      id
      name
      organizationId
      state
      type
      updatedAt
    }
    listMetadata {
      after
      before
    }
  }
}
```

```json language="json" title="Response" tab="2"
{
  "data": {
    "directoryConnections": {
      "data": [
        {
          "createdAt": "2024-01-01T00:00:00.000Z",
          "externalKey": "externalKey_example",
          "id": "id_01EHWNCE74X7JSDV0X3SZ3KJNY",
          "name": "name_example",
          "organizationId": "organizationId_01EHWNCE74X7JSDV0X3SZ3KJNY",
          "state": "state_example",
          "type": "type_example",
          "updatedAt": "2024-01-01T00:00:00.000Z"
        }
      ],
      "listMetadata": {
        "after": "after_example",
        "before": "before_example"
      }
    }
  }
}
```

:::

## List directory groups

List the groups of a Directory Sync connection.

:::code-group

```graphql language="graphql" title="Query" tab="1"
query DirectoryGroups($after: String, $before: String, $directoryId: ID!, $limit: Int, $order: PaginationOrder) {
  directoryGroups(after: $after, before: $before, directoryId: $directoryId, limit: $limit, order: $order) {
    data {
      createdAt
      directoryId
      id
      idpId
      name
      organizationId
      updatedAt
    }
    listMetadata {
      after
      before
    }
  }
}
```

```json language="json" title="Response" tab="2"
{
  "data": {
    "directoryGroups": {
      "data": [
        {
          "createdAt": "2024-01-01T00:00:00.000Z",
          "directoryId": "directoryId_01EHWNCE74X7JSDV0X3SZ3KJNY",
          "id": "id_01EHWNCE74X7JSDV0X3SZ3KJNY",
          "idpId": "idpId_example",
          "name": "name_example",
          "organizationId": "organizationId_01EHWNCE74X7JSDV0X3SZ3KJNY",
          "updatedAt": "2024-01-01T00:00:00.000Z"
        }
      ],
      "listMetadata": {
        "after": "after_example",
        "before": "before_example"
      }
    }
  }
}
```

:::

## List directory users

List the users of a Directory Sync connection.

:::code-group

```graphql language="graphql" title="Query" tab="1"
query DirectoryUsers($after: String, $before: String, $directoryId: ID!, $limit: Int, $order: PaginationOrder) {
  directoryUsers(after: $after, before: $before, directoryId: $directoryId, limit: $limit, order: $order) {
    data {
      createdAt
      directoryId
      email
      firstName
      id
      idpId
      lastName
      organizationId
      state
      updatedAt
      username
    }
    listMetadata {
      after
      before
    }
  }
}
```

```json language="json" title="Response" tab="2"
{
  "data": {
    "directoryUsers": {
      "data": [
        {
          "createdAt": "2024-01-01T00:00:00.000Z",
          "directoryId": "directoryId_01EHWNCE74X7JSDV0X3SZ3KJNY",
          "email": "email_example",
          "firstName": "firstName_example",
          "id": "id_01EHWNCE74X7JSDV0X3SZ3KJNY",
          "idpId": "idpId_example",
          "lastName": "lastName_example",
          "organizationId": "organizationId_01EHWNCE74X7JSDV0X3SZ3KJNY",
          "state": "state_example",
          "updatedAt": "2024-01-01T00:00:00.000Z",
          "username": "username_example"
        }
      ],
      "listMetadata": {
        "after": "after_example",
        "before": "before_example"
      }
    }
  }
}
```

:::

### Query directoryConnection

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | ID! | Yes |  |

#### Returns

| Field | Type | Description |
| --- | --- | --- |
| `createdAt` | DateTime! |  |
| `externalKey` | String! |  |
| `id` | ID! |  |
| `name` | String! |  |
| `organizationId` | ID! |  |
| `state` | String! | The linking state of the directory. |
| `type` | String! | The provider type of the directory. |
| `updatedAt` | DateTime! |  |

### Query directoryConnections

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `after` | String | No |  |
| `before` | String | No |  |
| `limit` | Int | No |  |
| `order` | PaginationOrder | No | Enum represents the pagination order. |
| `search` | String | No | Filter directories by name. |

#### Returns

| Field | Type | Description |
| --- | --- | --- |
| `data` | [Directory!]! | A Directory Sync connection within the current environment. |
| `listMetadata` | ListMetadata! |  |

### Query directoryGroups

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `after` | String | No |  |
| `before` | String | No |  |
| `directoryId` | ID! | Yes | The directory whose groups should be returned. |
| `limit` | Int | No |  |
| `order` | PaginationOrder | No | Enum represents the pagination order. |

#### Returns

| Field | Type | Description |
| --- | --- | --- |
| `data` | [DirectoryGroup!]! | A group provisioned through a Directory Sync connection. |
| `listMetadata` | ListMetadata! |  |

### Query directoryUsers

#### Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `after` | String | No |  |
| `before` | String | No |  |
| `directoryId` | ID! | Yes | The directory whose users should be returned. |
| `limit` | Int | No |  |
| `order` | PaginationOrder | No | Enum represents the pagination order. |

#### Returns

| Field | Type | Description |
| --- | --- | --- |
| `data` | [DirectoryUser!]! | A user provisioned through a Directory Sync connection. |
| `listMetadata` | ListMetadata! |  |