UPDATE (May 2019) The Google Docs API was officially launched in Feb 2019. The documentation is located at the link from my update in July below. A few weeks after launch, I produced a high-level video overview of what a mail merge application using the API would look like. (It s not a full-fledged G Suite Dev Show episode but does link to a working sample.)
UPDATE (Jul 2018) The Google Docs team pre-announced a forthcoming REST API at Google Cloud NEXT 18. Developers interested in getting into the early access program for the new API should register at https://developers.google.com/docs. The original answer below still stands as the REST API will become the second way you can access Google Docs programmatically.
Original answer (Mar 2017): (Most other answers are outdated.) Google Docs does not currently have a REST API, however developers can programmatically access (CRUD) documents using Google Apps Script, server-side JavaScript apps that are hosted at and run in Google s cloud. If you re new to Apps Script or to editing Google Docs with it, here are some learning resources:
- Your first script which creates & edits a Doc, then uses Gmail to send it
to you.
- I ve got 4 intro videos for you (mostly Sheets-flavored)
- Useful pages in the official docs
- See Google Docs add-ons that other developers have built
Simple example: if you have an existing Doc with a (Drive) file ID of DOCUMENT_ID_GOES_HERE
, here s how you d basically edit it with Apps Script, doing a pseudo "mail merge" of name & email into the document given placeholders {NAME}
and {ADDR}
:
function mergeNameEmail() {
// Open a document by ID
var doc = DocumentApp.openById(DOCUMENT_ID_GOES_HERE);
// Access the body of the document
var body = doc.getBody();
// Merge name & address from template
body.replaceText("{NAME}", "Ima Developer");
body.replaceText("{ADDR}", "123 Main St, Anytown, XX 00000");
}