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

# How do I watch for new files in Google Drive and send them to Parabola?

> Use a Google Apps Script to automatically detect new files in a Google Drive folder and email them to your Parabola flow using the Extract from email step.

You can set up a Google Apps Script that monitors a Google Drive folder for new files and automatically sends them to a Parabola flow via email. This is useful when you receive files from external partners or systems that drop files into a shared Drive folder.

## Prerequisites

* A Parabola flow with an **Extract from email** step configured (you'll need the generated email address)
* A Google Drive folder you want to monitor
* Access to [Google Apps Script](https://script.google.com)

## Step-by-step setup

<Steps>
  <Step title="Set up your Parabola flow">
    Create a flow with an **Extract from email** step and copy the generated inbound email address. This is the address the script will send files to.
  </Step>

  <Step title="Open Google Apps Script">
    Go to [script.google.com](https://script.google.com) and create a new project.
  </Step>

  <Step title="Paste the script">
    Replace the default code with the following script. Update `FOLDER_ID` with your Google Drive folder ID and `EMAIL` with your flow's generated email address:

    <Accordion title="Expand code block">
      ```javascript theme={null}
      const FOLDER_ID = 'YOUR_FOLDER_ID_HERE';       // Replace with your folder ID
      const EMAIL = 'example@inbound.parabola.io';   // Replace with your flow's generated email address

      function checkForNewFiles() {
        const props = PropertiesService.getScriptProperties();
        const lastChecked = props.getProperty('lastChecked');
        const now = new Date();

        // On first run, just record the time and exit
        if (!lastChecked) {
          props.setProperty('lastChecked', now.toISOString());
          Logger.log('First run — timestamp saved. New files after this will trigger emails.');
          return;
        }

        const folder = DriveApp.getFolderById(FOLDER_ID);
        const files = folder.getFiles();
        const lastCheckedDate = new Date(lastChecked);
        const newFiles = [];

        while (files.hasNext()) {
          const file = files.next();
          if (file.getDateCreated() > lastCheckedDate) {
            newFiles.push(file);
          }
        }

        if (newFiles.length > 0) {
          newFiles.forEach(file => sendEmailWithAttachment(file));
        }

        props.setProperty('lastChecked', now.toISOString());
      }

      function sendEmailWithAttachment(file) {
        const fileName = file.getName();
        const fileBlob = file.getBlob();

        GmailApp.sendEmail(
          EMAIL,
          `New file added: ${fileName}`,
          `A new file was added to your watched Google Drive folder.\n\nFile: ${fileName}\nAdded: ${file.getDateCreated()}`,
          {
            attachments: [fileBlob],
            name: 'Drive File Watcher'
          }
        );

        Logger.log(`Email sent for: ${fileName}`);
      }
      ```
    </Accordion>

    <Tip>
      To find your folder ID, open the folder in Google Drive and copy the string of characters after `folders/` in the URL.
    </Tip>
  </Step>

  <Step title="Run the script once manually">
    Click the **Run** button on `checkForNewFiles` to initialize the timestamp. This prevents the script from emailing all existing files on the first trigger run. You'll be asked to authorize permissions — click through to approve.
  </Step>

  <Step title="Set up a time-based trigger">
    1. In the Apps Script editor, click the **clock icon** (Triggers) in the left sidebar
    2. Click **+ Add Trigger**
    3. Set it to run `checkForNewFiles` on a **time-driven** trigger (e.g., every 5 or 15 minutes)

    <Frame>
      <img src="https://mintcdn.com/parabola-7119dfb0/fPccFqL74BrvPADC/images/apps-script-trigger-settings.png?fit=max&auto=format&n=fPccFqL74BrvPADC&q=85&s=21707ac3630ddbaaee33d3e67afb582f" alt="Apps Script trigger settings" width="1382" height="1368" data-path="images/apps-script-trigger-settings.png" />
    </Frame>
  </Step>
</Steps>

## Things to know

* **Large files** — Gmail has a 25 MB attachment limit. If you expect larger files, you can modify the script to send a Drive link instead of an attachment.
* **Google-native file types** — Google Docs, Sheets, and Slides need to be exported to a format like PDF before attaching. The script above handles standard file types (CSV, PDF, XLSX, etc.), but additional export logic is needed for native Google formats.
* **Polling delay** — Google Drive doesn't support true real-time triggers for file changes. The script polls on whatever interval you set in the trigger (e.g., every 5 minutes).
* **CC yourself on notifications** — To receive a copy of each email, add `cc: 'your-email@example.com'` to the options object in `sendEmailWithAttachment`.
* **Authentication** — You'll be asked to authorize permissions when you first run the script manually and again when the trigger fires for the first time.
