---
related_nodes: ["google_drive", "google_sheets", "google_slides"]
---

# Google Docs

Create, read, edit and trash Google Docs from workflows.

## When to Use

- Writing a report or summary from workflow results into a new document
- Reading a document's text for an AI step to summarise or answer from
- Filling a template document by replacing placeholders such as `[name]`
- Appending log entries or meeting notes to a running document
- Formatting text, building tables or lists with Google's own edit requests

## How It Works

The Google Docs node calls the Google Docs API; delete goes through Google Drive, which is the only API that removes files. It supports:

- **Create**: Create an empty document
- **Get**: Read the document's full structure, with the indexes edits need
- **GetText**: Read the document as plain text
- **InsertText**: Insert text at an index
- **ReplaceText**: Replace every occurrence of a text
- **DeleteText**: Delete the text between two indexes
- **AppendText**: Append text to the end of the body
- **BatchUpdate**: Apply a list of Google Docs API edit requests in one call
- **Delete**: Move the document to the Drive trash

Before using this node, add a Google OAuth connection in **Settings → Connections**.

## Configuration

**connection** - Google connection to use
- Select from Settings → Connections
- Agents should call `list_connections` and set `connection` to the returned `id` ULID
- Use `name` only for display; node configuration needs the `id`
- Must be a "google" connection type holding the `drive` scope, which covers Google Docs; a call it lacks the scope for fails with an error asking to reconnect the account
- Required

Validation notes:
- The node validates that `connection` is selected when you save.
- Operation fields are evaluated at runtime after interpolation; a blank required field fails the run before Google is called.

**operation** - Operation to perform
- `create`: Create a document
- `get`: Read the document's structure
- `get_text`: Read the document as plain text
- `insert_text`: Insert text at an index
- `replace_text`: Replace every occurrence of a text
- `delete_text`: Delete a range of text
- `append_text`: Append text to the end
- `batch_update`: Apply Google Docs edit requests
- `delete`: Move the document to the trash

Indexes count UTF-16 code units in the document body. The body starts at index 1. Read the `startIndex` and `endIndex` of each element with `get` before inserting or deleting by index.

### Operation: Create

**title** - Title of the new document
- Interpolatable from input
- Required

The document is created in the root of the user's Drive. Move it into a folder with the Google Drive node's `move_file`, using the returned `documentId` as the file ID.

### Operation: Get

**document_id** - Document ID
- The ID in the document's URL (`docs.google.com/document/d/<id>/edit`), or a Drive file ID
- Interpolatable from input
- Required

### Operation: Get Text

**document_id** - Document ID
- Interpolatable from input
- Required

### Operation: Insert Text

**document_id** - Document ID
- Interpolatable from input
- Required

**text** - Text to insert
- A newline starts a new paragraph
- Interpolatable from input

**index** - Position to insert at
- A whole number; 1 is the start of the body
- Interpolatable from input
- Required

### Operation: Replace Text

**document_id** - Document ID
- Interpolatable from input
- Required

**find** - Text to find
- Interpolatable from input
- Required

**replace_with** - Replacement text
- Empty removes every match
- Interpolatable from input

**match_case** - Match case exactly
- Default: `false`

### Operation: Delete Text

**document_id** - Document ID
- Interpolatable from input
- Required

**start_index** - First position to delete
- Interpolatable from input
- Required

**end_index** - Position after the last one deleted
- Greater than `start_index`
- Interpolatable from input
- Required

### Operation: Append Text

**document_id** - Document ID
- Interpolatable from input
- Required

**text** - Text to append at the end of the body
- Start it with a newline to begin a new paragraph
- Interpolatable from input

### Operation: Batch Update

**document_id** - Document ID
- Interpolatable from input
- Required

**requests** - JSON array of Google Docs API `Request` objects
- Applied in order, all or none
- Either JSON text, or a reference such as `{{ input.requests }}` to an array an earlier node built
- See Google's [documents.batchUpdate reference](https://developers.google.com/workspace/docs/api/reference/rest/v1/documents/request) for every request type
- Required

### Operation: Delete

**document_id** - Document ID
- Interpolatable from input
- Required

The document goes to the Drive trash and can be restored from there for 30 days.

### Retry

**retry** - Whether each Docs request is sent again after a failure that passes: a rate limit, a busy server, a dropped connection. Off by default; see [Retries](http_get.md#retries) for how attempts and waits work. Get and Get Text are reads, sent again freely. Create, the edits, Batch Update and Delete are writes, sent again only when Google refused them before acting: the connection never opened, or Google answered 425 or 429. The `google_docs` tool group takes the same setting.

## Inputs

**input** - Any input
- Used to trigger the node
- Data can be accessed for template interpolation
- Required

## Outputs

**output** - Google Docs result

For Create:
```json
{
  "documentId": "1AbCdEfGhIjKlMnOpQrStUvWxYz0123456789",
  "title": "Q3 Summary"
}
```

For Get: Google's full `Document` resource (`documentId`, `title`, `body.content` with `startIndex`/`endIndex` on every element, styles, lists and more).

For GetText:
```json
{
  "documentId": "1AbCdEfGhIjKlMnOpQrStUvWxYz0123456789",
  "title": "Q3 Summary",
  "text": "Revenue grew 12%.\nCosts held flat.\n"
}
```

For ReplaceText:
```json
{
  "documentId": "1AbCdEfGhIjKlMnOpQrStUvWxYz0123456789",
  "occurrencesChanged": 3
}
```

For InsertText, DeleteText, AppendText and BatchUpdate, one reply per request sent, as Google returns them (empty for requests that return nothing):
```json
{
  "documentId": "1AbCdEfGhIjKlMnOpQrStUvWxYz0123456789",
  "replies": [{}]
}
```

For Delete: the trashed Drive file (`id`, `name`, `mimeType`, `trashed: true`, and the other file fields the Google Drive node returns).

## Examples

### Write a Summary Document

```json
{
  "google_docs": {
    "connection": "01JABCDEF0123456789ABCDEFG",
    "operation": {
      "op": "create",
      "title": { "content": "Summary {{ input.date }}" }
    }
  }
}
```

Follow it with a second Google Docs node appending the text:

```json
{
  "google_docs": {
    "connection": "01JABCDEF0123456789ABCDEFG",
    "operation": {
      "op": "append_text",
      "document_id": { "content": "{{ create.output.documentId }}" },
      "text": { "content": "{{ ai.output.summary }}" }
    }
  }
}
```

### Fill a Template

```json
{
  "google_docs": {
    "connection": "01JABCDEF0123456789ABCDEFG",
    "operation": {
      "op": "replace_text",
      "document_id": { "content": "{{ copy.output.id }}" },
      "find": { "content": "[customer]" },
      "replace_with": { "content": "{{ input.customer_name }}" },
      "match_case": true
    }
  }
}
```

Copy the template first with the Google Drive node's `copy_file`, so the original stays untouched.

### Bold a Heading

```json
{
  "google_docs": {
    "connection": "01JABCDEF0123456789ABCDEFG",
    "operation": {
      "op": "batch_update",
      "document_id": { "content": "{{ input.document_id }}" },
      "requests": { "content": "[{\"updateTextStyle\": {\"range\": {\"startIndex\": 1, \"endIndex\": 12}, \"textStyle\": {\"bold\": true}, \"fields\": \"bold\"}}]" }
    }
  }
}
```

## Agent Tools

The `google_docs` tool group gives agents the same operations as tools: `docs_create`, `docs_get`, `docs_get_text`, `docs_insert_text`, `docs_replace_text`, `docs_delete_text`, `docs_append_text`, `docs_batch_update` and `docs_delete`, each prefixed with the connection's handle. Reads run freely; creates and edits are write; `docs_delete` is delete.

`docs_get` gives an agent a bounded outline rather than the full resource the node returns: `documentId`, `title`, `bodyEndIndex`, `elementCount`, and the first 100 top-level body elements, each with `startIndex`, `endIndex` and a `kind` (`paragraph` with its named style such as `HEADING_1`, `table` with `rows` and `columns`, `table_of_contents`, or `section_break`) carrying a text preview of at most 200 bytes. `docs_get_text` returns the full text.

## Notes

- Indexes shift after every edit: an insert moves everything after it. In one batch update, order deletes and inserts from the end of the document backwards.
- Get Text reads the first tab of a document with tabs.
- A connection made before Google Docs access was requested fails with an insufficient-permission error until the account is reconnected.
