# Document Index

The "Document Index" endpoint generates a comprehensive index of all documents within a specified Google Drive folder. By default, this endpoint will recursively index all subfolders, but you can choose to disable this behavior if desired. The response includes detailed metadata for each document and folder, making it easier to manage and access documents during processes like due diligence.

### Endpoint

```bash
POST /v1/drive/document-index
```

### Parameters

* **google\_drive\_folder** (required, string): The Google Drive folder ID that you want to index. This can be found from the Google Drive UI by navigating to the folder and copying the folder ID from the URL. The folder ID is the string of characters following `/folders/` in the URL.

  Example URL: `https://drive.google.com/drive/u/0/folders/1A2B3C4D5E6F7G8H9I`

  In this example, the folder ID is `1A2B3C4D5E6F7G8H9I`.
* **recursive** (optional, boolean): Specifies whether to index subfolders recursively. The default value is `true`. Set to `false` if you only want to index the documents in the specified folder without including subfolders.

**Note:** The user must be logged in with an account that is authorized to access the specified Google Drive folder.

### Example Request

```http
POST /v1/drive/document-index
{
  "google_drive_folder": "1A2B3C4D5E6F7G8H9I"
}
```

### Example Response

```json
{
  "folder_id": "1A2B3C4D5E6F7G8H9I",
  "folder_name": "Due Diligence Documents",
  "source": "Google_Drive",
  "document_index": [
    {
      "folder_id": "1A2B3C4D5E6F7G8H9I",
      "category": "Financial Reports",
      "source": "Google_Drive",
      "documents": [
        {
          "document_id": "1X2Y3Z4A5B6C7D8E9F",
          "document_name": "Q1 Financial Report.pdf",
          "document_url": "https://drive.google.com/file/d/1X2Y3Z4A5B6C7D8E9F/view",
          "date_created": "2024-01-15T10:00:00Z",
          "date_updated": "2024-02-01T14:00:00Z",
          "size": "2MB",
          "mime_type": "application/pdf",
          "source": "Google_Drive"
        },
        {
          "document_id": "2Y3Z4A5B6C7D8E9F1X",
          "document_name": "Q2 Financial Report.pdf",
          "document_url": "https://drive.google.com/file/d/2Y3Z4A5B6C7D8E9F1X/view",
          "date_created": "2024-04-15T10:00:00Z",
          "date_updated": "2024-05-01T14:00:00Z",
          "size": "2.5MB",
          "mime_type": "application/pdf",
          "source": "Google_Drive"
        }
      ],
      "subfolders": [
        {
          "folder_id": "2B3C4D5E6F7G8H9I1A",
          "subfolder_name": "Archived Reports",
          "source": "Google_Drive",
          "documents": [
            {
              "document_id": "3Z4A5B6C7D8E9F1X2Y",
              "document_name": "2019 Financial Report.pdf",
              "document_url": "https://drive.google.com/file/d/3Z4A5B6C7D8E9F1X2Y/view",
              "date_created": "2019-01-15T10:00:00Z",
              "date_updated": "2019-02-01T14:00:00Z",
              "size": "1.8MB",
              "mime_type": "application/pdf",
              "source": "Google_Drive"
            },
            {
              "document_id": "4A5B6C7D8E9F1X2Y3Z",
              "document_name": "2020 Financial Report.pdf",
              "document_url": "https://drive.google.com/file/d/4A5B6C7D8E9F1X2Y3Z/view",
              "date_created": "2020-01-15T10:00:00Z",
              "date_updated": "2020-02-01T14:00:00Z",
              "size": "2MB",
              "mime_type": "application/pdf",
              "source": "Google_Drive"
            }
          ]
        }
      ]
    },
    {
      "folder_id": "1A2B3C4D5E6F7G8H9I",
      "category": "Legal Documents",
      "source": "Google_Drive",
      "documents": [
        {
          "document_id": "5B6C7D8E9F1X2Y3Z4A",
          "document_name": "NDA.pdf",
          "document_url": "https://drive.google.com/file/d/5B6C7D8E9F1X2Y3Z4A/view",
          "date_created": "2024-03-01T09:30:00Z",
          "date_updated": "2024-03-10T11:45:00Z",
          "size": "350KB",
          "mime_type": "application/pdf",
          "source": "Google_Drive"
        },
        {
          "document_id": "6C7D8E9F1X2Y3Z4A5B",
          "document_name": "Contract Agreement.pdf",
          "document_url": "https://drive.google.com/file/d/6C7D8E9F1X2Y3Z4A5B/view",
          "date_created": "2024-03-15T11:00:00Z",
          "date_updated": "2024-03-20T12:30:00Z",
          "size": "1.2MB",
          "mime_type": "application/pdf",
          "source": "Google_Drive"
        }
      ]
    }
  ]
}
```

### Usage Notes

* **Google Drive Folder ID:** To obtain the correct folder ID, navigate to the desired folder in Google Drive and copy the folder ID from the URL. Ensure you have the necessary permissions to access the folder.
* **Metadata Included:** The response includes comprehensive metadata for each document and folder, such as `document_id`, `document_name`, `document_url`, `date_created`, `date_updated`, `size`, `mime_type`, `folder_id`, and `source`. This allows for easier document management and retrieval.
* **Recursive Indexing:** By default, the endpoint will index all documents within the folder and its subfolders. Use the `recursive` parameter to control whether subfolders should be indexed.

### Example Use Case: Due Diligence Document Index

In a due diligence process, it’s crucial to organize and review a vast number of documents across multiple categories, such as financial reports, legal agreements, and compliance certifications. By using the "Document Index" endpoint, you can automatically generate a detailed index of all files stored in a Google Drive folder designated for due diligence.

This index will not only categorize the documents but also provide important metadata like creation and update dates, file sizes, document IDs for direct retrieval, and direct URLs for easy access. This information can be invaluable for keeping track of document versions and ensuring all necessary materials are readily available to the due diligence team.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.corpdev.ai/corpdev.ai-docs/document-api/document-index.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
