> ## Documentation Index
> Fetch the complete documentation index at: https://docs.equa.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Drive Endpoints

> Google Drive integration for connecting, syncing, and managing folder sync configurations

> **Source:** `equa-server/modules/api/src/endpoints/google-drive-endpoints.ts`

<Warning>
  These endpoints are currently disabled in production. The source file exists but is
  commented out in the endpoint registration (`endpoints.ts`). These endpoints are
  documented here for reference and will become active when the feature is re-enabled.
</Warning>

# Google Drive Endpoints

Endpoints for connecting an organization's data room with Google Drive. Supports OAuth connection, folder browsing, sync configuration, manual sync triggers, and sync history.

All Google Drive endpoints require authentication.

## Connection

### Get Auth URL

```
GET /v1/organization/:organization/google-drive/auth-url
```

| Field      | Value              |
| ---------- | ------------------ |
| Auth       | Required           |
| Permission | `canEditDocuments` |

Get the Google OAuth URL to initiate the connection flow. Redirect the user to this URL to authorize Google Drive access.

**Response:**

```json theme={null}
{
  "url": "https://accounts.google.com/o/oauth2/v2/auth?..."
}
```

***

### Connect Google Drive

```
POST /v1/organization/:organization/google-drive/connect
```

| Field      | Value              |
| ---------- | ------------------ |
| Auth       | Required           |
| Permission | `canEditDocuments` |

Complete the OAuth flow by exchanging the authorization code for tokens. If a connection already exists, the tokens are refreshed.

**Request:**

```json theme={null}
{
  "organization": "uuid",
  "code": "google-authorization-code"
}
```

**Response:**

```json theme={null}
{
  "success": true,
  "connectionId": "uuid",
  "email": "user@gmail.com"
}
```

***

### Disconnect Google Drive

```
DELETE /v1/organization/:organization/google-drive/connection
```

| Field      | Value              |
| ---------- | ------------------ |
| Auth       | Required           |
| Permission | `canEditDocuments` |

Disconnect Google Drive from the organization. Deactivates the connection without deleting synced files.

***

### Get Connection Status

```
GET /v1/organization/:organization/google-drive/status
```

| Field      | Value                 |
| ---------- | --------------------- |
| Auth       | Required              |
| Permission | `canViewOrganization` |

Check whether Google Drive is connected and get sync configuration details.

**Response (connected):**

```json theme={null}
{
  "connected": true,
  "connectionId": "uuid",
  "email": "user@gmail.com",
  "lastSyncAt": "2025-06-15T10:30:00Z",
  "syncError": null,
  "syncConfigurations": [
    {
      "id": "uuid",
      "googleFolderId": "google-folder-id",
      "googleFolderName": "Company Documents",
      "targetDataRoomPath": "/synced/company-docs",
      "syncEnabled": true,
      "syncSubfolders": true,
      "lastSyncAt": "2025-06-15T10:30:00Z",
      "syncError": null
    }
  ]
}
```

**Response (not connected):**

```json theme={null}
{
  "connected": false
}
```

***

## Folder Browsing

### List Folders

```
GET /v1/organization/:organization/google-drive/folders
```

| Field      | Value                 |
| ---------- | --------------------- |
| Auth       | Required              |
| Permission | `canViewOrganization` |

Browse Google Drive folders. If `parentId` is omitted, returns root-level folders.

**Query parameters:**

| Parameter  | Type   | Description                                |
| ---------- | ------ | ------------------------------------------ |
| `parentId` | string | Google Drive folder ID to list children of |

***

## Sync Configuration

### Create Sync Config

```
POST /v1/organization/:organization/google-drive/sync-config
```

| Field      | Value              |
| ---------- | ------------------ |
| Auth       | Required           |
| Permission | `canEditDocuments` |

Create a folder sync configuration that maps a Google Drive folder to a data room path.

**Request:**

```json theme={null}
{
  "organization": "uuid",
  "googleFolderId": "google-folder-id",
  "googleFolderName": "Company Documents",
  "targetDataRoomPath": "/synced/company-docs",
  "syncSubfolders": true,
  "fileTypeFilter": "pdf,docx,xlsx"
}
```

**Response:**

```json theme={null}
{
  "success": true,
  "configurationId": "uuid"
}
```

***

### Update Sync Config

```
PATCH /v1/organization/:organization/google-drive/sync-config/:id
```

| Field      | Value              |
| ---------- | ------------------ |
| Auth       | Required           |
| Permission | `canEditDocuments` |

Update an existing sync configuration (enable/disable, change target path, toggle subfolder sync, update file type filter).

***

### Delete Sync Config

```
DELETE /v1/organization/:organization/google-drive/sync-config/:id
```

| Field      | Value              |
| ---------- | ------------------ |
| Auth       | Required           |
| Permission | `canEditDocuments` |

Soft-delete a sync configuration.

***

## Sync Operations

### Trigger Sync

```
POST /v1/organization/:organization/google-drive/sync
```

| Field      | Value              |
| ---------- | ------------------ |
| Auth       | Required           |
| Permission | `canEditDocuments` |

Manually trigger a sync operation. If `configurationId` is provided, only that configuration is synced; otherwise all enabled configurations are synced.

**Request:**

```json theme={null}
{
  "organization": "uuid",
  "configurationId": "uuid-or-omit-for-all"
}
```

**Response:**

```json theme={null}
{
  "results": [
    {
      "configurationId": "uuid",
      "filesProcessed": 15,
      "filesAdded": 3,
      "filesUpdated": 2,
      "filesSkipped": 10,
      "filesFailed": 0
    }
  ]
}
```

***

### Get Sync History

```
GET /v1/organization/:organization/google-drive/sync-history
```

| Field      | Value                 |
| ---------- | --------------------- |
| Auth       | Required              |
| Permission | `canViewOrganization` |

Get the sync history for the organization (last 50 entries). Optionally filter by `configurationId`.

**Query parameters:**

| Parameter         | Type   | Description                     |
| ----------------- | ------ | ------------------------------- |
| `configurationId` | string | Filter by sync configuration ID |

**Response:**

```json theme={null}
{
  "history": [
    {
      "id": "uuid",
      "configurationId": "uuid",
      "status": "completed",
      "errorMessage": null,
      "filesProcessed": 15,
      "filesAdded": 3,
      "filesUpdated": 2,
      "filesSkipped": 10,
      "filesFailed": 0,
      "startedAt": "2025-06-15T10:30:00Z",
      "completedAt": "2025-06-15T10:31:15Z",
      "triggeredAt": "2025-06-15T10:30:00Z"
    }
  ]
}
```
