Liking cljdoc? Tell your friends :D

goog.workspace.docs

Clojure wrapper for the Google Docs API (v1).

Provides idiomatic Clojure functions for creating, reading, and updating Google Docs through the batch update pattern.

Auth: use csl/scoped-delegated-credentials or csl/user-credentials with the appropriate scope:

  • DocsScopes/DOCUMENTS (full read/write access)
  • DocsScopes/DOCUMENTS_READONLY (read-only access)
  • DocsScopes/DRIVE (full Drive access — docs are Drive files)
  • DocsScopes/DRIVE_FILE (only files used with this app)
  • DocsScopes/DRIVE_READONLY (read-only Drive access)

All document mutations go through batch-update, which takes a vector of request maps (kebab-case keys, coerced to camelCase internally). Convenience builders (insert-text-request, delete-content-range-request, etc.) return plain Clojure maps for use with batch-update.

Enum-typed fields in data maps (e.g. named style types) should be passed as uppercase strings (e.g. "HEADING_1", "NORMAL_TEXT").

All functions return {:data ...} on success or {:error ...} on failure.

Clojure wrapper for the Google Docs API (v1).

Provides idiomatic Clojure functions for creating, reading, and updating
Google Docs through the batch update pattern.

Auth: use csl/scoped-delegated-credentials or csl/user-credentials with
the appropriate scope:
- DocsScopes/DOCUMENTS          (full read/write access)
- DocsScopes/DOCUMENTS_READONLY (read-only access)
- DocsScopes/DRIVE              (full Drive access — docs are Drive files)
- DocsScopes/DRIVE_FILE         (only files used with this app)
- DocsScopes/DRIVE_READONLY     (read-only Drive access)

All document mutations go through batch-update, which takes a vector of
request maps (kebab-case keys, coerced to camelCase internally). Convenience
builders (insert-text-request, delete-content-range-request, etc.) return
plain Clojure maps for use with batch-update.

Enum-typed fields in data maps (e.g. named style types) should be passed
as uppercase strings (e.g. "HEADING_1", "NORMAL_TEXT").

All functions return {:data ...} on success or {:error ...} on failure.
raw docstring

batch-updateclj

(batch-update client document-id requests & [opts])

Execute a batch of content updates on a document.

requests —a vector of request maps (kebab-case keys). Each map should have a single top-level key naming the operation: {:insert-text {:text "Hello" :location {:index 1}}} {:delete-content-range {:range {:start-index 5 :end-index 10}}}

Use convenience builders (insert-text-request, delete-content-range-request, etc.) to construct request maps, or build them directly as data.

Returns the batch update response including :replies (one per request) and :write-control (revision tracking for optimistic locking).

opts:

  • :fields —a partial response field mask string
  • :read-timeout-ms —int, override the HTTP client's default read timeout for this request.
Execute a batch of content updates on a document.

requests —a vector of request maps (kebab-case keys). Each map should
have a single top-level key naming the operation:
  {:insert-text {:text "Hello" :location {:index 1}}}
  {:delete-content-range {:range {:start-index 5 :end-index 10}}}

Use convenience builders (insert-text-request, delete-content-range-request,
etc.) to construct request maps, or build them directly as data.

Returns the batch update response including :replies (one per request)
and :write-control (revision tracking for optimistic locking).

opts:
- :fields          —a partial response field mask string
- :read-timeout-ms —int, override the HTTP client's default read timeout
  for this request.
raw docstring

create-documentclj

(create-document client doc-data & [opts])

Create a new empty document.

doc-data —map with kebab-case keys: :title —the document title

opts:

  • :fields —a partial response field mask string
  • :read-timeout-ms —int, override the HTTP client's default read timeout for this request.
Create a new empty document.

doc-data —map with kebab-case keys:
  :title —the document title

opts:
- :fields          —a partial response field mask string
- :read-timeout-ms —int, override the HTTP client's default read timeout
  for this request.
raw docstring

(create-footer-request section-break-location)

Build a request map to create a default footer at the given section break index.

Build a request map to create a default footer at the given section break index.
raw docstring

create-header-requestclj

(create-header-request section-break-location)

Build a request map to create a default header at the given section break index.

Build a request map to create a default header at the given section break index.
raw docstring

delete-content-range-requestclj

(delete-content-range-request start-index end-index)

Build a request map to delete content between start-index and end-index.

Build a request map to delete content between start-index and end-index.
raw docstring

docs-clientclj

(docs-client credentials)
(docs-client credentials opts)

Build an authenticated Docs v1 REST client.

credentials —a com.google.auth.oauth2.GoogleCredentials instance, typically from csl/scoped-delegated-credentials or csl/user-credentials.

opts (optional):

  • :read-timeout-ms per-client default read timeout (default 120000 / 120s)
  • :connect-timeout-ms per-client default connect timeout (default 30000 / 30s)

Per-request opts on individual call sites override the client-level defaults.

Build an authenticated Docs v1 REST client.

credentials —a com.google.auth.oauth2.GoogleCredentials instance, typically
from csl/scoped-delegated-credentials or csl/user-credentials.

opts (optional):
- :read-timeout-ms     per-client default read timeout (default 120000 / 120s)
- :connect-timeout-ms  per-client default connect timeout (default 30000 / 30s)

Per-request opts on individual call sites override the client-level defaults.
raw docstring

extract-textclj

(extract-text document)

Extract plain text from a document map returned by get-document.

Walks the body's structural elements, collecting all text runs. Tables are recursed into; cell text is included in reading order. TextRun content naturally includes newline characters at paragraph boundaries.

Returns an empty string for documents with no text content.

Extract plain text from a document map returned by get-document.

Walks the body's structural elements, collecting all text runs.
Tables are recursed into; cell text is included in reading order.
TextRun content naturally includes newline characters at paragraph
boundaries.

Returns an empty string for documents with no text content.
raw docstring

get-documentclj

(get-document client document-id)
(get-document client document-id opts)

Get a document's content and metadata by ID.

Returns the full document structure including body, headers, footers, and all content elements. Use extract-text to pull plain text.

opts:

  • :fields —a partial response field mask string (e.g. "documentId,title,body(content(paragraph(elements(textRun(content)))))"). Omitting it returns the full document, which can be megabytes for large documents — pass a narrow mask if you only need a subset.
Get a document's content and metadata by ID.

Returns the full document structure including body, headers, footers,
and all content elements. Use extract-text to pull plain text.

opts:
- :fields —a partial response field mask string (e.g.
  "documentId,title,body(content(paragraph(elements(textRun(content)))))").
  Omitting it returns the full document, which can be megabytes for large
  documents — pass a narrow mask if you only need a subset.
raw docstring

insert-table-requestclj

(insert-table-request rows columns index)

Build a request map to insert a table at the given index.

Build a request map to insert a table at the given index.
raw docstring

insert-text-requestclj

(insert-text-request text index)

Build a request map to insert text at the given index.

index —the zero-based content index (1 is the start of the document body).

Build a request map to insert text at the given index.

index —the zero-based content index (1 is the start of the document body).
raw docstring

replace-all-text-requestclj

(replace-all-text-request old-text
                          new-text
                          &
                          [{:keys [match-case] :or {match-case true}}])

Build a request map to replace all occurrences of old-text with new-text.

opts:

  • :match-case —boolean (default true)
Build a request map to replace all occurrences of old-text with new-text.

opts:
- :match-case —boolean (default true)
raw docstring

update-paragraph-style-requestclj

(update-paragraph-style-request style start-index end-index fields)

Build a request map to update paragraph style over a range.

style —map of paragraph style properties (e.g. {:alignment "CENTER"}) fields —field mask string (e.g. "alignment")

Build a request map to update paragraph style over a range.

style  —map of paragraph style properties (e.g. {:alignment "CENTER"})
fields —field mask string (e.g. "alignment")
raw docstring

update-text-style-requestclj

(update-text-style-request style start-index end-index fields)

Build a request map to update text style over a range.

style —map of text style properties (e.g. {:bold true :font-size {:magnitude 14 :unit "PT"}}) fields —field mask string (e.g. "bold,fontSize")

Build a request map to update text style over a range.

style  —map of text style properties (e.g. {:bold true :font-size {:magnitude 14 :unit "PT"}})
fields —field mask string (e.g. "bold,fontSize")
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close