# Insert Rich Link — Google Docs

> Insert a file smart chip (rich link) to a Google Drive file into a Google Doc. The chip shows the file's live title and icon, unlike a plain hyperlink. Use it to reference another Doc, Sheet, Slides deck, Drive file or Drive folder. Only…

- Key: `google_docs-insert-rich-link`
- Type: Action (Write)
- Version: 0.1.0
- App: Google Docs (`google_docs`) — https://pipedream.com/apps/google-docs.md
- This page (HTML): https://pipedream.com/apps/google-docs/actions/insert-rich-link
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/google_docs/actions/insert-rich-link/insert-rich-link.mjs

## Description

Insert a file smart chip (rich link) to a Google Drive file into a Google Doc. The chip shows the file's live title and icon, unlike a plain hyperlink. Use it to reference another Doc, Sheet, Slides deck, Drive file or Drive folder. Only Google Drive URLs are accepted: YouTube, Calendar, Maps and other websites fail with `The URL is invalid`, and `Error fetching chip data` means the file doesn't exist or this account can't open it. Get a document's URL from **Find Document** (`url`). Place the chip with **Placeholder** (replace text such as `{{spec}}` that you wrote with **Insert Text**) or with **Position**; in a multi-tab document either set **Tab ID** (from **List Tabs**) or use **Placeholder**. Example: call with documentId=`1AbC...`, fileUrl=`https://docs.google.com/document/d/1XyZ.../edit`, placeholder=`{{spec}}` -> returns `chipsInserted`, each chip's `tabId` and `index`, and the document `url`. [See the documentation](https://developers.google.com/workspace/docs/api/reference/rest/v1/documents/request#InsertRichLinkRequest)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `documentId` | `string` | Yes | The ID of the Google Doc. This is the long string in the document's URL: https://docs.google.com/document/d/{DOCUMENT_ID}/edit. Use Find Document to resolve a document's name to its ID. |
| `fileUrl` | `string` | Yes | URL of the Google Drive file or folder to link, e.g. https://docs.google.com/document/d/1XyZ.../edit, https://docs.google.com/spreadsheets/d/1XyZ.../edit, or https://drive.google.com/drive/folders/1XyZ.... A Google Doc's URL comes from Find Document (url); any other Drive file or folder URL works too. Google sets the chip's title from the file, so no title is needed. |
| `placeholder` | `string` | No | Existing text to replace with the chip, matched exactly (case-sensitive). Typically a placeholder you wrote with Insert Text, such as {{owner}}, or a name already in the document. Searches every tab unless Tab ID is set. When set, Position is ignored. This is the reliable way to put a chip mid-sentence: no character index needed. |
| `occurrence` | `string` | No | Which matches of Placeholder become chips: all (default) or first. |
| `position` | `string` | No | Where to insert the chip when no Placeholder is given: end to append to the end of the tab (default), beginning, or a numeric character index (e.g. 12) from Get Document. The chip joins the paragraph at that point, so to start a new line insert a newline with Insert Text first. |
| `tabId` | `string` | No | For a multi-tab document, the ID of the tab to insert into (e.g. t.0); get IDs from List Tabs, or use the ID returned by Create Tab. Required when the document has more than one tab and the chip is placed by Position: the tool will not guess, so a chip never lands in the first tab by accident. With Placeholder, omit it to search every tab. |
| `suggestMode` | `boolean` | No | Make the change as a suggestion (Google Docs Suggesting mode) that the document's editors can accept or reject, instead of editing the document directly. The response's suggestionIds lists the suggestions the change created or extended - an edit next to an existing suggestion can join it rather than create a new one. Pass the IDs to Resolve Suggestions, or use List Suggestions to see every open suggestion. While a suggestion is open, the document text this returns shows the suggested and the original text side by side. Set true to propose the edit, or leave false (default) to edit directly. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "google_docs",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "google_docs-insert-rich-link",
  arguments: {
    documentId: "Document ID",
    fileUrl: "File URL",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "google_docs-insert-rich-link",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    google_docs: { authProvisionId: "apn_xxxxxxx" },
    documentId: "Document ID",
    fileUrl: "File URL",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "google_docs-insert-rich-link",
    "configured_props": {
      "google_docs": { "authProvisionId": "apn_xxxxxxx" },
      "documentId": "Document ID",
      "fileUrl": "File URL"
    }
  }'
```

---

- App: https://pipedream.com/apps/google-docs.md · All apps: https://pipedream.com/apps
