Software Engineering & Digital Products for Global Enterprises since 2006
CMMi Level 3SOC 2ISO 27001
Menu
View all services
Staff Augmentation
Embed senior engineers in your team within weeks.
Dedicated Teams
A ring-fenced squad with PM, leads, and engineers.
Build-Operate-Transfer
We hire, run, and transfer the team to you.
Contract-to-Hire
Try the talent. Convert when you're ready.
ForceHQ
Skill testing, interviews and ranking — powered by AI.
RoboRingo
Build, deploy and monitor voice agents without code.
MailGovern
Policy, retention and compliance for enterprise email.
Vishing
Test and train staff against AI-driven voice attacks.
CyberForceHQ
Continuous, adaptive security training for every team.
IDS Load Balancer
Built for Multi Instance InDesign Server, to distribute jobs.
AutoVAPT.ai
AI agent for continuous, automated vulnerability and penetration testing.
Salesforce + InDesign Connector
Bridge Salesforce data into InDesign to design print catalogues at scale.
View all solutions
Banking, Financial Services & Insurance
Cloud, digital and legacy modernisation across financial entities.
Healthcare
Clinical platforms, patient engagement, and connected medical devices.
Pharma & Life Sciences
Trial systems, regulatory data, and field-force enablement.
Professional Services & Education
Workflow automation, learning platforms, and consulting tooling.
Media & Entertainment
AI video processing, OTT platforms, and content workflows.
Technology & SaaS
Product engineering, integrations, and scale for tech companies.
Retail & eCommerce
Shopify, print catalogues, web-to-print, and order automation.
View all industries
Blog
Engineering notes, opinions, and field reports.
Case Studies
How clients shipped — outcomes, stack, lessons.
White Papers
Deep-dives on AI, talent models, and platforms.
Portfolio
Selected work across industries.
View all resources
About Us
Who we are, our story, and what drives us.
Co-Innovation
How we partner to build new products together.
Careers
Open roles and what it's like to work here.
News
Press, announcements, and industry updates.
Leadership
The people steering MetaDesign.
Locations
Gurugram, Brisbane, Detroit and beyond.
Contact Us
Talk to sales, hiring, or partnerships.
Request TalentStart a Project
Web Development

Create a Web API with Google Apps Script and Use Google Drive as CMS

AG
Amit Gupta
Technical Content Writer
October 15, 2024
11 min read
Create a Web API with Google Apps Script and Use Google Drive as CMS — Web Development | MetaDesign Solutions

Rethinking Content Management

When developers need a Content Management System (CMS) for a new website or application, they usually reach for heavy-duty solutions like WordPress, Contentful, or Strapi. While powerful, these platforms often introduce unnecessary complexity, require dedicated database hosting, and force non-technical users to learn a completely new interface.

But what if you could use a tool that everyone in your organization already knows how to use? Google Drive and Google Docs offer a world-class collaborative editing experience. By leveraging Google Apps Script (GAS), developers can expose Google Drive folders and Google Docs as a fully functional, serverless REST API, effectively transforming Google Workspace into a highly collaborative, zero-cost headless CMS.

What is Google Apps Script (GAS)?

Google Apps Script is a rapid application development platform based on JavaScript. It runs directly on Google's cloud infrastructure and provides built-in, native objects to interact with Google Workspace applications (Docs, Sheets, Gmail, Drive, etc.).

The beauty of GAS is that it requires absolutely zero server setup. You don't need AWS, you don't need a Node.js server, and you don't have to worry about scaling. When you write a script, Google executes it. More importantly, GAS allows you to deploy scripts as "Web Apps," meaning they can listen for standard HTTP GET and POST requests, making them perfect for building lightweight APIs.

The Architecture: Drive as a Database, GAS as the API

The architecture for this headless CMS is remarkably simple yet highly effective.

The Database (Google Drive): You create a specific folder in Google Drive. Inside this folder, you create standard Google Docs. These documents represent your "blog posts" or "web pages." The content is written naturally, utilizing headings, bold text, and lists.

The API Layer (Google Apps Script): You write a standalone Apps Script that acts as the router. When an external frontend application sends an HTTP GET request to the Apps Script URL, the script reads the contents of the Google Drive folder, opens the relevant Google Docs, extracts the text (or HTML), packages it into a JSON payload, and returns it to the client.

Writing the doGet() Web API Function

To create a Web API in Google Apps Script, you must define a specific function called doGet(e). This function is automatically triggered whenever an HTTP GET request hits your published Web App URL.

Inside doGet(e), the e parameter contains the query string parameters. For example, if a user requests ?articleId=12345, your script can extract that ID using e.parameter.articleId. Once the script has the ID, it uses the DriveApp and DocumentApp services to locate the file, read its contents, and construct a JavaScript object. Finally, to return the data to the client, you must return a ContentService.createTextOutput() object, setting the MimeType to JSON.

Fetching and Parsing Google Docs Content

Fetching raw text from a Google Doc is easy, but raw text isn't very useful for a web page—you lose all formatting. The real power comes from extracting the structured data.

Using the DocumentApp service, you can iterate through the elements of a document (paragraphs, list items, tables). As you iterate, you can check the element's type. If it's a HEADING1, you wrap the text in an <h1> tag. If it's a LIST_ITEM, you wrap it in an <li> tag. By building a simple parser within your Apps Script, you can dynamically convert a standard Google Doc into clean, semantic HTML that your frontend application can safely inject using dangerouslySetInnerHTML (in React) or equivalent methods.

Transform Your Publishing Workflow

Our experts can help you build scalable, API-driven publishing systems tailored to your business.

Book a free consultation

Handling Authentication and CORS

When deploying your Apps Script as a Web App, you are presented with access settings. To use it as a public API, you must set "Execute as" to "Me" and "Who has access" to "Anyone".

This configuration means the script accesses your Google Drive using your permissions, but anyone with the API URL can trigger the script without needing to log into Google. Because the script is running on script.google.com, Google handles Cross-Origin Resource Sharing (CORS) automatically, allowing your frontend (hosted on Vercel, Netlify, etc.) to fetch the data seamlessly via standard JavaScript fetch() calls.

Consuming the API in a Frontend Application

Once the API is deployed, consuming it is no different than fetching data from Contentful or a Node.js server. In a modern framework like Next.js or Nuxt, you can fetch the data during the build process (Static Site Generation) or on the server (Server-Side Rendering).

Because Google Apps Script does have rate limits (and is not designed to handle thousands of requests per second), the best practice is to use Static Site Generation (SSG) or implement a strong caching layer (like Redis or Next.js ISR). Your server fetches the Google Doc JSON payload once, caches the HTML, and serves the cached version to your thousands of users, ensuring blazing-fast load times while avoiding Google's quota limits.

Conclusion: A Cost-Effective CMS Alternative

Using Google Drive and Apps Script as a headless CMS is an incredibly elegant solution for small to medium-sized projects, internal company portals, and rapid prototypes. It provides a familiar editing interface for content creators, requires zero database hosting fees, and integrates perfectly with modern frontend frameworks.

However, for massive enterprise applications requiring complex relational data, strict version control, and high-throughput real-time APIs, traditional CMS architectures remain necessary. At MetaDesign Solutions, our cloud architecture experts can help you evaluate your requirements and build the perfect headless CMS solution—whether it's an innovative Google Workspace integration or a highly scalable enterprise platform. Contact us today to optimize your content delivery workflow.

FAQ

Frequently Asked Questions

Common questions about this topic, answered by our engineering team.

Google Apps Script is a JavaScript-based cloud scripting platform provided by Google. It allows developers to write code that interacts directly with Google Workspace applications (Docs, Sheets, Drive) and can be deployed as serverless Web APIs.

By creating a folder in Google Drive to act as your database, content creators can write articles using standard Google Docs. A custom Google Apps Script then acts as an API, fetching those documents, converting them to HTML/JSON, and serving them to a frontend website.

Yes. Executing Google Apps Scripts and deploying them as Web Apps incurs no additional hosting costs. It is entirely covered under your standard Google account or Google Workspace subscription, subject to standard daily execution quotas.

When you deploy a GAS Web App and set access to "Anyone", Google automatically handles CORS (Cross-Origin Resource Sharing). This allows any frontend application (like a React or Vue app) to successfully make `fetch()` requests to your script URL.

Google Apps Script is subject to rate limits and execution time quotas (usually 6 minutes per execution). It is not designed to handle high-frequency, real-time database queries. Therefore, it is highly recommended to use Static Site Generation (SSG) or caching on your frontend.

Discussion

Join the Conversation

Ready when you are

Let's build something great together.

A 30-minute call with a principal engineer. We'll listen, sketch, and tell you whether we're the right partner — even if the answer is no.

Talk to a strategist
Need help with your project? Let's talk.
Book a call