Googledocs

Learn how to use Googledocs with Composio

Overview

SLUG: GOOGLEDOCS

Description

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

Authentication Details

client_id
stringRequired
client_secret
stringRequired
oauth_redirect_uri
stringDefaults to https://backend.composio.dev/api/v1/auth-apps/add
scopes
stringDefaults to https://www.googleapis.com/auth/documents,https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/userinfo.email
bearer_token
string
token
stringRequired

Connecting to Googledocs

Create an auth config

Use the dashboard to create an auth config for the Googledocs toolkit. This allows you to connect multiple Googledocs accounts to Composio for agents to use.

1

Select App

Navigate to the Googledocs toolkit page and click “Setup Integration”.

2

Configure Auth Config Settings

Select among the supported auth schemes of and configure them here.

3

Create and Get auth config ID

Click “Create Integration”. After creation, copy the displayed ID starting with ac_. This is your auth config ID. This is not a sensitive ID — you can save it in environment variables or a database. This ID will be used to create connections to the toolkit for a given user.

Connect Your Account

Using OAuth2

1from composio import Composio
2
3# Replace these with your actual values
4googledocs_auth_config_id = "ac_YOUR_GOOGLEDOCS_CONFIG_ID" # Auth config ID created above
5user_id = "0000-0000-0000" # UUID from database/application
6
7composio = Composio()
8
9
10def authenticate_toolkit(user_id: str, auth_config_id: str):
11 connection_request = composio.connected_accounts.initiate(
12 user_id=user_id,
13 auth_config_id=auth_config_id,
14 )
15
16 print(
17 f"Visit this URL to authenticate Googledocs: {connection_request.redirect_url}"
18 )
19
20 # This will wait for the auth flow to be completed
21 connection_request.wait_for_connection(timeout=15)
22 return connection_request.id
23
24
25connection_id = authenticate_toolkit(user_id, googledocs_auth_config_id)
26
27# You can also verify the connection status using:
28connected_account = composio.connected_accounts.get(connection_id)
29print(f"Connected account: {connected_account}")

Using Bearer Token

1from composio import Composio
2
3# Auth config ID created above
4googledocs_auth_config_id = "ac_YOUR_GOOGLEDOCS_CONFIG_ID"
5
6# UUID from database/application
7user_id = "0000-0000-0000"
8
9composio = Composio()
10
11
12def authenticate_toolkit(user_id: str, auth_config_id: str):
13 # Replace this with a method to retrieve the Bearer Token from the user.
14 bearer_token = input("[!] Enter bearer token")
15 connection_request = composio.connected_accounts.initiate(
16 user_id=user_id,
17 auth_config_id=auth_config_id,
18 config={"auth_scheme": "BEARER_TOKEN", "val": bearer_token}
19 )
20 print(f"Successfully connected Googledocs for user {user_id}")
21 print(f"Connection status: {connection_request.status}")
22
23 return connection_request.id
24
25
26connection_id = authenticate_toolkit(user_id, googledocs_auth_config_id)
27
28# You can verify the connection using:
29connected_account = composio.connected_accounts.get(connection_id)
30print(f"Connected account: {connected_account}")

Tools

Executing tools

To prototype you can execute some tools to see the responses and working on the Googledocs toolkit’s playground

Python
1from composio import Composio
2from openai import OpenAI
3import json
4
5openai = OpenAI()
6composio = Composio()
7
8# User ID must be a valid UUID format
9user_id = "0000-0000-0000" # Replace with actual user UUID from your database
10
11tools = composio.tools.get(user_id=user_id, toolkits=["GOOGLEDOCS"])
12
13print("[!] Tools:")
14print(json.dumps(tools))
15
16def invoke_llm(task = "What can you do?"):
17 completion = openai.chat.completions.create(
18 model="gpt-4o",
19 messages=[
20 {
21 "role": "user",
22 "content": task, # Your task here!
23 },
24 ],
25 tools=tools,
26 )
27
28 # Handle Result from tool call
29 result = composio.provider.handle_tool_calls(user_id=user_id, response=completion)
30 print(f"[!] Completion: {completion}")
31 print(f"[!] Tool call result: {result}")
32
33invoke_llm()

Tool List

Tool Name: Copy Google Document

Description

Tool to create a copy of an existing google document. use this to duplicate a document, for example, when using an existing document as a template. the copied document will have a default title (e.g., 'copy of [original title]') if no new title is provided, and will be placed in the user's root google drive folder.

Action Parameters

document_id
stringRequired
title
string

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Create Document Markdown

Description

Creates a new google docs document, optionally initializing it with a title and content provided as markdown text.

Action Parameters

markdown_text
stringRequired
title
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Create Footnote

Description

Tool to create a new footnote in a google document. use this when you need to add a footnote at a specific location or at the end of the document body.

Action Parameters

documentId
stringRequired
endOfSegmentLocation
object
location
object

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Create Header

Description

Tool to create a new header in a google document. use this tool when you need to add a header to a document, optionally specifying the section it applies to.

Action Parameters

createHeader
objectRequired
documentId
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Create named range

Description

Tool to create a new named range in a google document. use this to assign a name to a specific part of the document for easier reference or programmatic manipulation.

Action Parameters

documentId
stringRequired
name
stringRequired
rangeEndIndex
integerRequired
rangeSegmentId
string
rangeStartIndex
integerRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Create Paragraph Bullets

Description

Tool to add bullets to paragraphs within a specified range in a google document. use when you need to format a list or a set of paragraphs as bullet points.

Action Parameters

createParagraphBullets
objectRequired
document_id
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Delete Content Range in Document

Description

Tool to delete a range of content from a google document. use when you need to remove a specific portion of text or other structural elements within a document.

Action Parameters

document_id
stringRequired
range
objectRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Delete Header

Description

Deletes the header from the specified section or the default header if no section is specified. use this tool to remove a header from a google document.

Action Parameters

document_id
stringRequired
header_id
stringRequired
tab_id
string

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Delete Named Range

Description

Tool to delete a named range from a google document. use when you need to remove a previously defined named range by its id or name.

Action Parameters

deleteNamedRange
objectRequired
document_id
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Delete Paragraph Bullets

Description

Tool to remove bullets from paragraphs within a specified range in a google document. use when you need to clear bullet formatting from a section of a document.

Action Parameters

document_id
stringRequired
range
objectRequired
tab_id
string

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Delete Table

Description

Tool to delete an entire table from a google document. use when you have the document id and the specific start and end index of the table element to be removed. the table's range can be found by inspecting the document's content structure.

Action Parameters

document_id
stringRequired
segment_id
string
tab_id
string
table_end_index
integerRequired
table_start_index
integerRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Delete Table Column

Description

Tool to delete a column from a table in a google document. use this tool when you need to remove a specific column from an existing table within a document.

Action Parameters

document_id
stringRequired
requests
arrayRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Delete Table Row

Description

Tool to delete a row from a table in a google document. use when you need to remove a specific row from an existing table.

Action Parameters

documentId
stringRequired
tableCellLocation
objectRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get Charts from Spreadsheet

Description

Tool to retrieve a list of all charts from a specified google sheets spreadsheet. use when you need to get chart ids and their specifications for embedding or referencing elsewhere, such as in google docs.

Action Parameters

spreadsheet_id
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Insert Inline Image

Description

Tool to insert an image from a given uri at a specified location in a google document as an inline image. use when you need to add an image to a document programmatically.

Action Parameters

documentId
stringRequired
location
objectRequired
objectSize
object
uri
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Insert Page Break

Description

Tool to insert a page break into a google document. use when you need to start new content on a fresh page, such as at the end of a chapter or section.

Action Parameters

documentId
stringRequired
insertPageBreak
objectRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Insert Table in Google Doc

Description

Tool to insert a table into a google document. use when you need to add a new table at a specific location or at the end of a segment (like document body, header, or footer) in a document.

Action Parameters

columns
integerRequired
documentId
stringRequired
index
integer
insertAtEndOfSegment
boolean
rows
integerRequired
segmentId
string
tabId
string

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Insert Table Column

Description

Tool to insert a new column into a table in a google document. use this tool when you need to add a column to an existing table at a specific location.

Action Parameters

document_id
stringRequired
requests
arrayRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Insert Text into Document

Description

Tool to insert a string of text at a specified location within a google document. use when you need to add new text content to an existing document.

Action Parameters

document_id
stringRequired
insertion_index
integerRequired
text_to_insert
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: List Charts from Spreadsheet

Description

Tool to retrieve a list of charts with their ids and metadata from a google sheets spreadsheet. use to identify charts available for embedding into google docs.

Action Parameters

fields_mask
stringDefaults to sheets(properties(sheetId,title),charts(chartId,spec(title,altText)))
spreadsheet_id
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Replace All Text in Document

Description

Tool to replace all occurrences of a specified text string with another text string throughout a google document. use when you need to perform a global find and replace operation within a document.

Action Parameters

document_id
stringRequired
find_text
stringRequired
match_case
booleanRequired
replace_text
stringRequired
search_by_regex
boolean
tab_ids
array

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Replace Image in Document

Description

Tool to replace a specific image in a document with a new image from a uri. use when you need to update an existing image within a google doc.

Action Parameters

document_id
stringRequired
replace_image
objectRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Unmerge Table Cells

Description

Tool to unmerge previously merged cells in a table. use this when you need to revert merged cells in a google document table back to their individual cell states.

Action Parameters

document_id
stringRequired
tableRange
objectRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Update Document Style

Description

Tool to update the overall document style, such as page size, margins, and default text direction. use when you need to modify the global style settings of a google document.

Action Parameters

document_id
stringRequired
document_style
objectRequired
fields
stringRequired
tab_id
string

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Update Table Row Style

Description

Tool to update the style of a table row in a google document. use when you need to modify the appearance of specific rows within a table, such as setting minimum row height or marking rows as headers.

Action Parameters

documentId
stringRequired
updateTableRowStyle
objectRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Create a document

Description

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).

Action Parameters

text
stringRequired
title
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Get document by id

Description

Retrieves an existing google document by its id; will error if the document is not found.

Action Parameters

id
stringRequired

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Search Documents

Description

Search for google documents using various filters including name, content, date ranges, and more.

Action Parameters

created_after
string
include_trashed
boolean
max_results
integerDefaults to 10
modified_after
string
order_by
stringDefaults to modifiedTime desc
query
string
shared_with_me
boolean
starred_only
boolean

Action Response

data
objectRequired
error
string
successful
booleanRequired

Tool Name: Update Document Markdown

Description

Replaces the entire content of an existing google docs document with new markdown text; requires edit permissions for the document.

Action Parameters

document_id
stringRequired
new_markdown_text
stringRequired

Action Response

data
object
document_id
string
error
string
successful
booleanRequired

Tool Name: Update existing document

Description

Applies programmatic edits, such as text insertion, deletion, or formatting, to a specified google doc using the `batchupdate` api method.

Action Parameters

document_id
stringRequired
editDocs
arrayRequired

Action Response

data
object
document_id
string
error
string
successful
booleanRequired