# Google Docs (/integrations/google_docs)

Use [Google Docs](https://docs.google.com) in Sim to read, create, and update documents. Workflows can insert text, tables, images, and page breaks; find and replace text; and apply text styling.

## OAuth scopes \[#oauth-scopes]

Sim requests these scopes when someone connects a Google Docs account. For a self-hosted deployment, register your own app with the provider using the settings below. See [Integrations and OAuth](/platform/self-hosting/integrations-oauth) for setup.

| Setting | Value |
| - | - |
| Redirect URI | `<NEXT_PUBLIC_APP_URL>/api/auth/oauth2/callback/google-docs` |
| Environment variables | `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` |

| Scope | Description |
| - | - |
| `https://www.googleapis.com/auth/userinfo.email` | View email address |
| `https://www.googleapis.com/auth/userinfo.profile` | View basic profile info |
| `https://www.googleapis.com/auth/drive.file` | View and manage Google Drive files you open or create with Sim |
| `https://www.googleapis.com/auth/drive` | View, edit, create, and delete all Google Drive files |

## Use the block \[#usage-instructions]

Read, write, and create documents, insert text, tables, images, and page breaks, find and replace text, and apply text styling.

## Actions \[#actions]

### Read Google Docs Document \[#read-google-docs-document]

Read content from a Google Docs document

#### Input \[#input]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | Google Docs document ID |
| `includeTabsContent` | boolean | No | When true, reads every tab of the document: content holds the text of all tabs in order and tabs lists each tab with its own text. Default: false (only the first tab is read). |
| `suggestionsViewMode` | string | No | How suggested edits appear in the returned text. One of: DEFAULT_FOR_CURRENT_ACCESS (default), SUGGESTIONS_INLINE, PREVIEW_SUGGESTIONS_ACCEPTED, PREVIEW_WITHOUT_SUGGESTIONS. |

#### Output \[#output]

| Parameter | Type | Description |
| - | - | - |
| `content` | string | Extracted document text content |
| `metadata` | json | Document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |
| ↳ `revisionId` | string | Revision ID of the document as read |
| `tabs` | array | Every tab in the document, depth-first (populated only when includeTabsContent is true) |
| ↳ `tabId` | string | Tab ID |
| ↳ `title` | string | Tab title |
| ↳ `parentTabId` | string | Parent tab ID |
| ↳ `index` | number | Zero-based index within the parent |
| ↳ `nestingLevel` | number | Depth of the tab |
| ↳ `content` | string | Extracted text content of the tab |

### Write to Google Docs Document \[#write-to-google-docs-document]

Append content to a Google Docs document. Content is inserted literally; Markdown is not interpreted. For formatted output from Markdown, use the Create operation with the markdown toggle enabled.

#### Input \[#input-1]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to write to |
| `content` | string | Yes | The content to write to the document |
| `tabId` | string | No | ID of the tab to append the content to (from Read with includeTabsContent). When omitted, the first tab is used. |

#### Output \[#output-1]

| Parameter | Type | Description |
| - | - | - |
| `updatedContent` | boolean | Indicates if document content was updated successfully |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Create Google Docs Document \[#create-google-docs-document]

Create a new Google Docs document

#### Input \[#input-2]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `title` | string | Yes | The title of the document to create |
| `content` | string | No | The content of the document to create |
| `folderSelector` | string | No | Google Drive folder ID to create the document in (e.g., 1ABCxyz...) |
| `folderId` | string | No | The ID of the folder to create the document in (internal use) |
| `markdown` | boolean | No | When true, content is interpreted as Markdown and converted to formatted Google Docs content (headings, bold/italic, lists, tables, links, code blocks, blockquotes). Default: false (content inserted as plain text). |

#### Output \[#output-2]

| Parameter | Type | Description |
| - | - | - |
| `metadata` | json | Created document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Insert Text into Google Docs Document \[#insert-text-into-google-docs-document]

Insert text at a specific index in a Google Docs document. When no index is provided, text is appended to the end of the document. Text is inserted literally; Markdown is not interpreted.

#### Input \[#input-3]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to insert text into |
| `text` | string | Yes | The text to insert |
| `index` | number | No | The character index (the document body starts at index 1) at which to insert the text. When omitted, text is appended to the end of the document. |
| `tabId` | string | No | ID of the tab to insert the text into (from Read with includeTabsContent). When omitted, the first tab is used. |

#### Output \[#output-3]

| Parameter | Type | Description |
| - | - | - |
| `updatedContent` | boolean | Indicates if text was inserted successfully |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Find and Replace Text in Google Docs Document \[#find-and-replace-text-in-google-docs-document]

Replace all occurrences of a search string with new text across a Google Docs document.

#### Input \[#input-4]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to update |
| `searchText` | string | Yes | The text to find |
| `replaceText` | string | No | The text to replace matches with. Use an empty string to delete matches. |
| `matchCase` | boolean | No | Whether the search should be case sensitive. Defaults to false. |
| `searchByRegex` | boolean | No | When true, the search text is treated as a regular expression. Defaults to false. |
| `tabId` | string | No | ID of a tab to limit the replacement to (from Read with includeTabsContent). When omitted, matches are replaced in all tabs. |

#### Output \[#output-4]

| Parameter | Type | Description |
| - | - | - |
| `occurrencesChanged` | number | The number of occurrences that were replaced |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Insert Table into Google Docs Document \[#insert-table-into-google-docs-document]

Insert an empty table with the given number of rows and columns into a Google Docs document. When no index is provided, the table is appended to the end of the document.

#### Input \[#input-5]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to insert the table into |
| `rows` | number | Yes | The number of rows in the table |
| `columns` | number | Yes | The number of columns in the table |
| `index` | number | No | The character index (the document body starts at index 1) at which to insert the table. When omitted, the table is appended to the end of the document. |
| `tabId` | string | No | ID of the tab to insert the table into (from Read with includeTabsContent). When omitted, the first tab is used. |

#### Output \[#output-5]

| Parameter | Type | Description |
| - | - | - |
| `updatedContent` | boolean | Indicates if the table was inserted successfully |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Insert Image into Google Docs Document \[#insert-image-into-google-docs-document]

Insert an inline image from a public URL into a Google Docs document. The image must be publicly accessible and under 50 MB. When no index is provided, the image is appended to the end of the document.

#### Input \[#input-6]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to insert the image into |
| `imageUrl` | string | Yes | The publicly accessible URL of the image to insert |
| `index` | number | No | The character index (the document body starts at index 1) at which to insert the image. When omitted, the image is appended to the end of the document. |
| `width` | number | No | Optional image width in points (PT) |
| `height` | number | No | Optional image height in points (PT) |
| `tabId` | string | No | ID of the tab to insert the image into (from Read with includeTabsContent). When omitted, the first tab is used. |

#### Output \[#output-6]

| Parameter | Type | Description |
| - | - | - |
| `objectId` | string | The ID of the inserted inline image object |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Insert Page Break into Google Docs Document \[#insert-page-break-into-google-docs-document]

Insert a page break into a Google Docs document. When no index is provided, the page break is appended to the end of the document.

#### Input \[#input-7]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to insert the page break into |
| `index` | number | No | The character index (the document body starts at index 1) at which to insert the page break. When omitted, the page break is appended to the end of the document. |
| `tabId` | string | No | ID of the tab to insert the page break into (from Read with includeTabsContent). When omitted, the first tab is used. |

#### Output \[#output-7]

| Parameter | Type | Description |
| - | - | - |
| `updatedContent` | boolean | Indicates if the page break was inserted successfully |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Apply Text Style in Google Docs Document \[#apply-text-style-in-google-docs-document]

Apply bold, italic, underline, and/or font size to a range of text in a Google Docs document, identified by its start and end character index.

#### Input \[#input-8]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to update |
| `startIndex` | number | Yes | The start character index (the document body starts at index 1) of the range to style (inclusive) |
| `endIndex` | number | Yes | The end character index of the range to style (exclusive) |
| `bold` | boolean | No | Whether to make the text bold |
| `italic` | boolean | No | Whether to make the text italic |
| `underline` | boolean | No | Whether to underline the text |
| `fontSize` | number | No | The font size to apply, in points (PT) |

#### Output \[#output-8]

| Parameter | Type | Description |
| - | - | - |
| `updatedContent` | boolean | Indicates if the text style was applied successfully |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Update Paragraph Style in Google Docs Document \[#update-paragraph-style-in-google-docs-document]

Apply a named paragraph style (such as a heading or title) and/or alignment to the paragraphs overlapping a range of text in a Google Docs document, identified by its start and end character index.

#### Input \[#input-9]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to update |
| `startIndex` | number | Yes | The start character index (the document body starts at index 1) of the range to style (inclusive) |
| `endIndex` | number | Yes | The end character index of the range to style (exclusive) |
| `namedStyleType` | string | No | The named paragraph style to apply. One of: NORMAL_TEXT, TITLE, SUBTITLE, HEADING_1, HEADING_2, HEADING_3, HEADING_4, HEADING_5, HEADING_6. |
| `alignment` | string | No | The paragraph alignment to apply. One of: LEFT, CENTER, RIGHT, JUSTIFY. |

#### Output \[#output-9]

| Parameter | Type | Description |
| - | - | - |
| `updatedContent` | boolean | Indicates if the paragraph style was applied successfully |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Create Paragraph Bullets in Google Docs Document \[#create-paragraph-bullets-in-google-docs-document]

Add bulleted or numbered list formatting to the paragraphs overlapping a range of text in a Google Docs document, using a chosen bullet glyph preset.

#### Input \[#input-10]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to update |
| `startIndex` | number | Yes | The start character index (the document body starts at index 1) of the range to bullet (inclusive) |
| `endIndex` | number | Yes | The end character index of the range to bullet (exclusive) |
| `bulletPreset` | string | No | The bullet glyph preset to apply. Defaults to BULLET_DISC_CIRCLE_SQUARE. Examples: BULLET_DISC_CIRCLE_SQUARE, BULLET_CHECKBOX, NUMBERED_DECIMAL_ALPHA_ROMAN, NUMBERED_DECIMAL_NESTED. |

#### Output \[#output-10]

| Parameter | Type | Description |
| - | - | - |
| `updatedContent` | boolean | Indicates if the bullets were applied successfully |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Delete Paragraph Bullets in Google Docs Document \[#delete-paragraph-bullets-in-google-docs-document]

Remove bullet or numbered list formatting from the paragraphs overlapping a range of text in a Google Docs document, identified by its start and end character index.

#### Input \[#input-11]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to update |
| `startIndex` | number | Yes | The start character index (the document body starts at index 1) of the range to clear bullets from (inclusive) |
| `endIndex` | number | Yes | The end character index of the range to clear bullets from (exclusive) |

#### Output \[#output-11]

| Parameter | Type | Description |
| - | - | - |
| `updatedContent` | boolean | Indicates if the bullets were removed successfully |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Delete Content Range in Google Docs Document \[#delete-content-range-in-google-docs-document]

Delete all content between a start and end character index in a Google Docs document. The endIndex is exclusive and must be greater than the startIndex.

#### Input \[#input-12]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to delete content from |
| `startIndex` | number | Yes | The start character index (the document body starts at index 1) of the range to delete (inclusive) |
| `endIndex` | number | Yes | The end character index of the range to delete (exclusive) |

#### Output \[#output-12]

| Parameter | Type | Description |
| - | - | - |
| `updatedContent` | boolean | Indicates if the content range was deleted successfully |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Create Named Range in Google Docs Document \[#create-named-range-in-google-docs-document]

Create a named range over a span of content in a Google Docs document so it can be referenced or deleted later. The name may be 1-256 characters and need not be unique.

#### Input \[#input-13]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to update |
| `name` | string | Yes | The name of the range to create (1-256 characters) |
| `startIndex` | number | Yes | The start character index (the document body starts at index 1) of the range (inclusive) |
| `endIndex` | number | Yes | The end character index of the range (exclusive) |

#### Output \[#output-13]

| Parameter | Type | Description |
| - | - | - |
| `namedRangeId` | string | The ID of the created named range |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |

### Delete Named Range in Google Docs Document \[#delete-named-range-in-google-docs-document]

Delete one or more named ranges from a Google Docs document by their ID or by name. Provide exactly one of namedRangeId or name; deleting by name removes all ranges sharing that name. The content itself is not removed.

#### Input \[#input-14]

| Parameter | Type | Required | Description |
| - | - | - | - |
| `documentId` | string | Yes | The ID of the document to update |
| `namedRangeId` | string | No | The ID of the named range to delete. Provide exactly one of namedRangeId or namedRangeName. |
| `namedRangeName` | string | No | The name of the named range(s) to delete. All ranges sharing this name are removed. Provide exactly one of namedRangeId or namedRangeName. |

#### Output \[#output-14]

| Parameter | Type | Description |
| - | - | - |
| `updatedContent` | boolean | Indicates if the named range(s) were deleted successfully |
| `metadata` | json | Updated document metadata including ID, title, and URL |
| ↳ `documentId` | string | Google Docs document ID |
| ↳ `title` | string | Document title |
| ↳ `mimeType` | string | Document MIME type |
| ↳ `url` | string | Document URL |
