NAME

Google::RestApi::DocsApi1 - API to Google Docs API V1.

SYNOPSIS

Basic Setup

use Google::RestApi;
use Google::RestApi::DocsApi1;

# Create the REST API instance
my $rest_api = Google::RestApi->new(
  config_file => '/path/to/config.yaml',
);

# Create the Docs API instance
my $docs_api = Google::RestApi::DocsApi1->new(api => $rest_api);

Creating and Opening Documents

# Create a new document
my $doc = $docs_api->create_document(title => 'My Document');

# Open an existing document by ID
my $doc = $docs_api->open_document(id => 'document_id');

# Get document content
my $content = $doc->get();

Batch Updates

# Queue up changes and submit them together
$doc->insert_text(text => 'Hello, World!', index => 1);
$doc->insert_text(text => "\n\nThis is a paragraph.", index => 14);
$doc->submit_requests();

# Style the text
$doc->update_text_style(
  range  => { startIndex => 1, endIndex => 14 },
  style  => { bold => JSON::MaybeXS::true() },
  fields => 'bold',
);
$doc->submit_requests();

Find and Replace

$doc->replace_all_text(
  find        => 'old text',
  replacement => 'new text',
);
$doc->submit_requests();

Listing and Deleting Documents

# List documents via Drive
my @docs = $docs_api->documents();
my @docs = $docs_api->documents(name => 'My Document');

# Delete a document
$docs_api->delete_document($document_id);

DESCRIPTION

Google::RestApi::DocsApi1 provides a Perl interface to the Google Docs API V1. It enables document management including:

  • Document creation and retrieval

  • Batch updates (insert text, delete content, formatting)

  • Find and replace operations

  • Table, header, footer, and section management

  • Named range management

  • Document listing and deletion via Drive API

It is assumed that you are familiar with the Google Docs API: https://developers.google.com/docs/api/reference/rest

Architecture

The API uses a two-level object model:

DocsApi1 (top-level)
  |-- open_document(id => ...)    -> Document
  |-- create_document(title => ...) -> Document

Document objects inherit from Google::RestApi::Request for batch request queuing. Requests are queued and submitted together via submit_requests().

NAVIGATION

SUBROUTINES

new(%args)

Creates a new DocsApi1 instance.

my $docs_api = Google::RestApi::DocsApi1->new(api => $rest_api);

%args consists of:

  • api Google::RestApi: Required. A configured RestApi instance.

  • drive <object>: Optional. A Drive API instance for listing/deleting documents.

  • endpoint <string>: Optional. Override the default Docs API endpoint.

api(%args)

Low-level method to make API calls. You would not normally call this directly unless making a Google API call not currently supported by this framework.

%args consists of:

  • uri <string>: Path segments to append to the Docs endpoint.

  • %args: Additional arguments passed to Google::RestApi's api() (content, params, method, etc).

Returns the response hash from the Google API.

create_document(%args)

Creates a new Google Docs document.

my $doc = $docs_api->create_document(title => 'My Document');

%args consists of:

  • title|name <string>: The title (or name) of the new document.

Returns a Document object for the created document.

open_document(%args)

Opens an existing document by ID.

my $doc = $docs_api->open_document(id => 'document_id');

%args are passed to the Document constructor.

Returns a Document object.

delete_document(document_id<string>)

Deletes the document from Google Drive.

delete_all_documents([document_name<string>])

Deletes all documents with the given names from Google Drive.

Returns the number of documents deleted.

delete_all_documents_by_filters([filters<arrayref>])

Deletes all documents matching the given Drive query filters.

Returns the number of documents deleted.

documents_by_filter(%args)

Lists documents matching a Drive query filter, combined with the document MIME type filter.

%args consists of:

  • filter <string>: Optional. A Drive query filter string.

  • max_pages <int>: Optional. Maximum pages to fetch (default 0 = unlimited).

  • page_callback <coderef>: Optional. Called with the result hashref for each page. Return false to stop pagination. See "PAGE CALLBACKS" in Google::RestApi.

  • params <hashref>: Optional. Additional query parameters passed to the Drive API.

Returns a list of file hashrefs with id and name.

documents(%args)

Lists documents, optionally filtered by name.

%args consists of:

  • name <string>: Optional. Filter by document name.

  • max_pages <int>: Optional. Maximum pages to fetch (default 0 = unlimited).

  • page_callback <coderef>: Optional. Called with the result hashref for each page. Return false to stop pagination. See "PAGE CALLBACKS" in Google::RestApi.

  • params <hashref>: Optional. Additional query parameters passed to the Drive API.

Returns a list of file hashrefs with id and name.

drive()

Returns a DriveApi3 instance for file operations. Lazily created if not provided.

rest_api()

Returns the underlying Google::RestApi instance.

transaction()

Returns the last API transaction details.

stats()

Returns API call statistics.

reset_stats()

Resets API call statistics.

SEE ALSO

AUTHORS

  • Robin Murray mvsjes@cpan.org

COPYRIGHT

Copyright (c) 2019-2026 Robin Murray. All rights reserved.

This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.