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:
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.(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:
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.(create-document client doc-data & [opts])Create a new empty document.
doc-data —map with kebab-case keys: :title —the document title
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-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.
(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.
(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.
(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):
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.
(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.
(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:
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.
(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.
(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).
(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:
Build a request map to replace all occurrences of old-text with new-text. opts: - :match-case —boolean (default true)
(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")(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")cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |