# Fetch Document

### **Overview**

The **Fetch Document Node** is responsible for retrieving the **actual content** of a document using its **documentId**. While the **Storage Read Node** retrieves the **documentId** from storage, this node takes that documentId and **returns a pre-signed URL**, allowing developers to access the actual file securely.

🔹 **Key Purpose:**\
✅ Fetch the **actual document file** that was previously stored.\
✅ Generate a **pre-signed URL** for **secure document access**.\
✅ Enable document viewing in **a document viewer or AI processing pipeline**.

#### **Common Workflow Pattern for Fetch Document Usage**

1️⃣ **Retrieve the documentId** using the **Storage Read Node (or from previous workflow execution, variables)**\
2️⃣ **Pass the documentId** to the **Fetch Document Node** to obtain the **pre-signed URL**.\
3️⃣ **Use the pre-signed URL** to display the document in a **document viewer** or process it further in an AI workflow.

🔹 **Example Use-Case:** A **loan processing system** retrieves a previously submitted **financial statement**. The **Storage Read Node** fetches the **documentId**, and the **Fetch Document Node** generates a **pre-signed URL**, which is used to display the document in a viewer for verification.

### **Configurations**

| Field           | Description                                                                                                                             |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| **Document ID** | The **unique identifier** of the document, retrieved using the **Storage Read Node**. This ID is required to fetch the actual document. |

#### **Execution Flow:**

1️⃣ The **Fetch Document Node** receives a **documentId** as input.\
2️⃣ It **generates a pre-signed URL**, allowing secure access to the actual document.\
3️⃣ The pre-signed URL can be **used in a document viewer** or **passed to another workflow node** for further processing.

#### **Output Format:**

```json
{
  "documentUrl": "https://storage.example.com/pre-signed-url"
}
```

* **documentUrl** → A secure, temporary link to access the document.

🔹 **Important Note:**\
✔ The **pre-signed URL is time-limited** for security reasons.\
✔ Developers should use the **documentUrl immediately or refresh it when needed**.

### **Example Use-Cases**

#### **Use-Case 1: Displaying a KYC Document in a Document Viewer**

A **loan processing workflow** requires a **loan officer to review a user’s submitted KYC documents** (e.g., Passport, Address Proof) before approval.

**Configuration:**

| Field           | Value                                  |
| --------------- | -------------------------------------- |
| **Document ID** | `fa5d0517-a479-49a5-b06e-9ed599f8e57a` |

**Execution Process:**

1️⃣ The **Storage Read Node** retrieves the **documentId** of the stored KYC document.\
2️⃣ The **Fetch Document Node** generates a **pre-signed URL** for secure document access.\
3️⃣ The **document URL is displayed in a document viewer** for manual review.

***

#### **Use-Case 2: Extracting Information from a Stored Invoice**

An AI-powered **invoice processing system** needs to **extract key financial data** from a previously uploaded invoice.

**Configuration:**

| Field           | Value                                  |
| --------------- | -------------------------------------- |
| **Document ID** | `b85c7029-df3a-49ab-a45e-3bdfb79d6b7a` |

**Execution Process:**

1️⃣ The **Storage Read Node** fetches the **documentId** of the invoice.\
2️⃣ The **Fetch Document Node** generates a **pre-signed URL** for secure access.\
3️⃣ The **document URL is passed to an OCR-based AI model**, which extracts text and numeric values.

***

#### **Use-Case 3: Automating the Retrieval of Financial Statements**

A **business loan underwriting system** requires AI models to **analyze past financial statements** stored in the system.

**Configuration:**

| Field           | Value                                  |
| --------------- | -------------------------------------- |
| **Document ID** | `c94a8223-ea5b-4cc5-b36f-7dcf54bfa2e4` |

**Execution Process:**

1️⃣ The **Storage Read Node** retrieves the **documentId** of the financial statement.\
2️⃣ The **Fetch Document Node** generates a **pre-signed URL** for AI processing.\
3️⃣ The **document is analyzed by an AI model** to assess financial health and eligibility.

### **Key Takeaways for Developers**

✅ **Retrieves Actual Document Content** – Unlike the **Storage Read Node**, which returns only the **documentId**, the **Fetch Document Node** generates a **pre-signed URL** for **secure document access**.

✅ **Enables Secure & Temporary Access** – The generated **pre-signed URL is time-limited**, ensuring that documents remain **protected and cannot be accessed indefinitely**.

✅ **Seamless Integration with AI & Document Processing** – Works alongside **AI models, OCR tools, and document viewers**, allowing for **automated processing, manual review, or AI-driven extraction**.

By leveraging the **Fetch Document Node**, developers can **efficiently retrieve, process, and display documents**, making AI-driven workflows **more powerful, secure, and intelligent**. 🚀
