# Google Docs on boxd

> Google Docs is a cloud-based word processor with real-time collaboration, version history, and integration with other Google Workspace apps.

- Page: https://boxd.sh/integrations/googledocs/
- CLI: `run googledocs` (43 commands, 36 marked common)
- SDK: `import { googledocs } from "@boxd/run"`; every parameter and response type is at `@boxd/run/googledocs`
- Triggers: 10
- Connect: `run auth googledocs` (Sign in with Google Docs), or https://app.boxd.sh/integrations/detail/googledocs
- All integrations: https://boxd.sh/integrations/ (Markdown: https://boxd.sh/integrations/index.md)

## From the shell

```sh
run auth googledocs      # once: prints a link to connect your account
run googledocs           # list its commands
run googledocs get-document-plaintext --help
```

Parameters are flags (`--flag value`); object and array parameters take a JSON string. Output is YAML, or JSON with `--json`. Calls use your own connection; `--scope <name>` uses a connection shared with your team.

## From a script

```ts
import { googledocs } from "@boxd/run";

const result = await googledocs.getDocumentPlaintext({ document_id: "…" });
console.log(result);

googledocs.on("document-created", async (event) => {
  // New Document Created: runs on this machine, once per event
  console.log(event);
});
```

Run it with `run googledocs.run.ts`. A script that calls `.on()` keeps running as a job and handles each event.

## Commands

Required flags are listed; `run googledocs <command> --help` lists the optional ones. "common" marks what `run googledocs` shows without `--all`.

| Command | SDK method | Required flags | Optional | Description |
|---|---|---|---|---|
| `copy-document` ·common | `googledocs.copyDocument()` | `--document-id` | 2 | Create a copy of an existing Google Document |
| `create-and-populate-table` ·common | `googledocs.createAndPopulateTable()` | `--cellData` `--columns` `--documentId` `--rows` | 4 | Creates a new table in a Google Document and populates its cells with provided text data in a single operation |
| `create-document` | `googledocs.createDocument()` | `--title` | 1 | Creates a new Google Docs document using the provided title as filename and inserts the initial text at the beginning if non-empty, returning the document's ID and metadata (excluding body content) |
| `create-document-markdown` ·common | `googledocs.createDocumentMarkdown()` | `--title` | 2 | Creates a new Google Docs document, optionally initializing it with a title and content provided as Markdown text |
| `create-document2` ·common ·deprecated | `googledocs.createDocument2()` | `--title` | 0 | Use create-document instead |
| `create-footer` ·common | `googledocs.createFooter()` | `--document-id` `--type` | 1 | Create a new footer in a Google Document |
| `create-footnote` ·common | `googledocs.createFootnote()` | `--documentId` | 2 | Create a new footnote in a Google Document |
| `create-header` ·common | `googledocs.createHeader()` | `--documentId` | 3 | Create a new header in a Google Document, optionally with text content |
| `create-named-range` ·common | `googledocs.createNamedRange()` | `--documentId` `--name` `--rangeEndIndex` `--rangeStartIndex` | 2 | Create a new named range in a Google Document |
| `create-paragraph-bullets` ·common | `googledocs.createParagraphBullets()` | `--createParagraphBullets` `--document-id` | 1 | Add bullets to paragraphs within a specified range in a Google Document |
| `create-tab` ·common | `googledocs.createTab()` | `--document-id` | 1 | Creates a new tab in a Google Docs document |
| `delete-content-range` ·common | `googledocs.deleteContentRange()` | `--document-id` `--range` | 0 | Delete a range of content from a Google Document |
| `delete-footer` ·common | `googledocs.deleteFooter()` | `--document-id` `--footer-id` | 1 | Delete a footer from a Google Document |
| `delete-header` ·common | `googledocs.deleteHeader()` | `--document-id` `--header-id` | 1 | Deletes the header from the specified section or the default header if no section is specified |
| `delete-named-range` ·common | `googledocs.deleteNamedRange()` | `--deleteNamedRange` `--document-id` | 0 | Delete a named range from a Google Document |
| `delete-paragraph-bullets` ·common | `googledocs.deleteParagraphBullets()` | `--document-id` `--range` | 1 | Remove bullets from paragraphs within a specified range in a Google Document |
| `delete-tab` ·common | `googledocs.deleteTab()` | `--document-id` `--tab-id` | 0 | Deletes a tab from a Google Document |
| `delete-table-column` ·common | `googledocs.deleteTableColumn()` | `--document-id` `--requests` | 0 | Delete a column from a table in a Google Document |
| `delete-table-row` ·common | `googledocs.deleteTableRow()` | `--documentId` `--tableCellLocation` | 0 | Delete a row from a table in a Google Document |
| `export-document-as-pdf` ·common | `googledocs.exportDocumentAsPdf()` | `--file-id` | 1 | Export a Google Docs file as PDF using the Google Drive API |
| `get-document-by-id` | `googledocs.getDocumentById()` | `--id` | 1 | Retrieves an existing Google Document by its ID; will error if the document is not found |
| `get-document-end-index` | `googledocs.getDocumentEndIndex()` | `--document-id` | 2 | Retrieves the end index and paragraph structure of a Google Document or specific segment |
| `get-document-plaintext` ·common | `googledocs.getDocumentPlaintext()` | `--document-id` | 8 | Retrieve a Google Doc by ID and return a best-effort plain-text rendering |
| `insert-image-in-table-cell` ·common | `googledocs.insertImageInTableCell()` | `--document-id` `--table-cell-location` `--uri` | 2 | Inserts an image from a given URI into a specific table cell in a Google Document |
| `insert-inline-image` ·common | `googledocs.insertInlineImage()` | `--documentId` `--location` `--uri` | 1 | Insert an image from a given URI at a specified location in a Google Document as an inline image |
| `insert-page-break` ·common | `googledocs.insertPageBreak()` | `--documentId` `--insertPageBreak` | 0 | Insert a page break into a Google Document |
| `insert-table-action` ·common | `googledocs.insertTableAction()` | `--columns` `--documentId` `--rows` | 4 | Insert a table into a Google Document |
| `insert-table-column` ·common | `googledocs.insertTableColumn()` | `--document-id` `--requests` | 0 | Insert a new column into a table in a Google Document |
| `insert-table-row` ·common | `googledocs.insertTableRow()` | `--document-id` `--requests` | 0 | Inserts a new row into a table in a Google Document at a specified location |
| `insert-text-action` ·common | `googledocs.insertTextAction()` | `--document-id` `--text-to-insert` | 4 | Insert a string of text at a specified location within a Google Document |
| `insert-text-in-table-cell` ·common | `googledocs.insertTextInTableCell()` | `--column-index` `--document-id` `--row-index` `--table-start-index` `--text` | 1 | Inserts text into a specific cell of a table in a Google Document by row and column position |
| `list-spreadsheet-charts` ·common | `googledocs.listSpreadsheetCharts()` | `--spreadsheet-id` | 0 | Retrieve a list of all charts from a specified Google Sheets spreadsheet |
| `replace-all-text` ·common | `googledocs.replaceAllText()` | `--document-id` `--find-text` `--replace-text` | 3 | Replace all occurrences of a specified text string with another text string throughout a Google Document |
| `replace-image` ·common | `googledocs.replaceImage()` | `--document-id` `--replace-image` | 0 | Replace a specific image in a document with a new image from a URI |
| `search-documents` | `googledocs.searchDocuments()` | — | 11 | Search for Google Documents using various filters including name, content, date ranges, and more |
| `unmerge-table-cells` ·common | `googledocs.unmergeTableCells()` | `--documentId` `--tableRange` | 0 | Unmerge previously merged cells in a table |
| `update-document-batch` ·common ·deprecated | `googledocs.updateDocumentBatch()` | `--document-id` `--requests` | 1 | Use UpdateExistingDocument instead |
| `update-document-markdown` | `googledocs.updateDocumentMarkdown()` | `--id` `--markdown` | 1 | Replaces the entire content of an existing Google Docs document with new Markdown text; requires edit permissions for the document |
| `update-document-section-markdown` ·common | `googledocs.updateDocumentSectionMarkdown()` | `--document-id` `--markdown-text` | 3 | Insert or replace a section of a Google Docs document with Markdown content |
| `update-document-style` ·common | `googledocs.updateDocumentStyle()` | `--document-id` `--document-style` | 2 | Update the overall document style, such as page size, margins, and default text direction |
| `update-existing-document` | `googledocs.updateExistingDocument()` | `--document-id` `--edit-docs` | 0 | Applies programmatic edits, such as text insertion, deletion, or formatting, to a specified Google Doc using the `batchUpdate` API method |
| `update-tab-properties` | `googledocs.updateTabProperties()` | `--document-id` `--tab-id` `--tab-properties` | 1 | Updates properties of a document tab such as title, parent tab, index, and icon emoji |
| `update-table-row-style` ·common | `googledocs.updateTableRowStyle()` | `--documentId` `--updateTableRowStyle` | 0 | Update the style of a table row in a Google Document |

## Triggers

`googledocs.on("<event>", handler)` in a script; required config goes before the handler as an object.

| Event | Name | Required config | Description |
|---|---|---|---|
| `"document-created"` | New Document Created | — | Triggers when a new Google Doc is created |
| `"document-deleted"` | Document Deleted | — | Triggers when an existing Google Doc is deleted (moved to trash) |
| `"document-placeholder-filled"` | Document Placeholder Filled | `document_id` `placeholder_pattern` | Triggers when a Google Doc's plain text changes such that a configured placeholder token/pattern is no longer present (i.e., the document ha |
| `"document-search-update"` | Document Search Update | `query` | Triggers when a Google Doc matching a user-defined search query is newly created or updated since the last poll |
| `"document-structure-changed"` | Document Structure Changed | `document_id` | Triggers when a Google Doc's structure changes (headers/footers added/removed, tables/images count changes) |
| `"document-updated"` | Document Updated | — | Triggers when an existing Google Doc is updated or modified |
| `"document-word-count-threshold"` | Document Word Count Threshold | `document_id` | Triggers when a Google Doc's word/character count crosses a user-defined threshold |
| `"folder-created"` | New Folder Created in Root | — | Triggers when a new folder is created in the root folder of Google Drive |
| `"keyword-detected"` | Keyword Detected in Document | `document_id` `keyword` | Triggers when a specific keyword or phrase first appears in a Google Doc |
| `"page-added"` | New Document Added | — | Triggers when a new Google Doc is added/created |

## Docs

- [run CLI](https://docs.boxd.sh/cli/run): Call connected integrations from the shell, connect new ones, and run automations.
- [Quickstart](https://docs.boxd.sh/guides/integrations/quickstart): Connect an integration, call it from the shell, and turn a script into an automation.
- [Connections](https://docs.boxd.sh/guides/integrations/connections): Connect an account once, for yourself or for your whole organization.
- [Scripts](https://docs.boxd.sh/guides/automations/scripts): Typed integrations, triggers, schedules and state in a .run.ts file.
- [Jobs](https://docs.boxd.sh/guides/automations/jobs): How a script becomes a background job: states, retries, sleep and wake.
- [Beyond the catalog](https://docs.boxd.sh/guides/automations/beyond-the-catalog): Reach your own APIs, databases and cloud accounts from a script.
