Skip to main content

Overview

The Google Apps Script serves as the backend for SpendWisely George, providing:
  • Data persistence in Google Sheets
  • RESTful API endpoints via Web App deployment
  • AI-powered transaction processing using Gemini API
  • User settings management

Prerequisites

  • A Google Account
  • A Google Sheet for storing transactions
  • A Gemini API key (for AI features)

Sheet Structure

Your Google Sheet should have the following columns:
ColumnNameTypeDescription
ADateDateTransaction timestamp
BDescriptionStringTransaction description
CAmountNumberTransaction amount
DCategoryStringCategory (Food, Transport, Tech, Invest, Income, Misc)
ETypeStringCREDIT or DEBIT
The first row should contain headers. The script automatically skips the header row when processing data.

Deployment Steps

1

Create or Open Your Google Sheet

Navigate to Google Sheets and create a new spreadsheet or open an existing one.Add the column headers in the first row:
  • A1: Date
  • B1: Description
  • C1: Amount
  • D1: Category
  • E1: Type
2

Get Your Sheet ID

Copy your Google Sheet ID from the URL:
https://docs.google.com/spreadsheets/d/[SHEET_ID]/edit
The Sheet ID is the long string between /d/ and /edit.
3

Open Apps Script Editor

In your Google Sheet, go to:Extensions → Apps ScriptThis opens the Google Apps Script editor in a new tab.
4

Paste the Script Code

Delete any existing code in the editor and paste the entire Google Apps Script code.
Make sure to update the SHEET_ID constant (line 14) with your actual Sheet ID:
const SHEET_ID = "YOUR_SHEET_ID_HERE";
5

Save the Project

Click the save icon or press Ctrl+S (Windows) / Cmd+S (Mac).Name your project (e.g., “SpendWisely George Backend”).
6

Deploy as Web App

  1. Click Deploy → New deployment
  2. Click the gear icon next to “Select type” and choose Web app
  3. Configure the deployment:
    • Description: “SpendWisely George API”
    • Execute as: Me (your Google account)
    • Who has access: Anyone
  4. Click Deploy
7

Authorize the Script

Google will ask you to authorize the script:
  1. Click Authorize access
  2. Select your Google account
  3. Click Advanced if you see a warning
  4. Click Go to [Project Name] (unsafe)
  5. Click Allow
8

Copy the Web App URL

After deployment, you’ll see a Web app URL. It looks like:
https://script.google.com/macros/s/[DEPLOYMENT_ID]/exec
Copy this URL - you’ll need it to configure the frontend application.
9

Configure Script Properties (Optional)

To set up AI features and default settings:
  1. In the Apps Script editor, click Project Settings (gear icon)
  2. Scroll to Script Properties
  3. Click Add script property and add:
    • GEMINI_KEY: Your Gemini API key
    • DAILY_BUDGET: Default daily budget (e.g., “350”)
    • PRIVACY_MODE: “true” or “false” (defaults to true)

Configuration Variables

Sheet ID

google_script.js:14
const SHEET_ID = "1u8avtUDehdZYSDDbIv0hoVyhBorUDptZDFh3ngp1gLo";
Replace this with your actual Google Sheet ID.

Script Properties

The following properties are stored using PropertiesService.getScriptProperties():
GEMINI_KEY
string
required
Your Google Gemini API key for AI-powered features
DAILY_BUDGET
string
default:"350"
Default daily budget amount
PRIVACY_MODE
string
default:"true"
Enable/disable privacy mode (“true” or “false”)

Testing Your Deployment

Test your deployment using curl or Postman:
curl https://script.google.com/macros/s/YOUR_DEPLOYMENT_ID/exec
Expected response:
{
  "balance": 0,
  "expenses": [],
  "budget": "350",
  "privacy": true
}

Updating Your Deployment

When you make changes to the script:
  1. Save your changes in the Apps Script editor
  2. Click Deploy → Manage deployments
  3. Click the edit icon (pencil) next to your active deployment
  4. Update the Version to “New version”
  5. Click Deploy
The Web App URL remains the same, but you must create a new version for changes to take effect.

Troubleshooting

Error: “Authorization required”

Solution: Ensure you’ve authorized the script and set “Execute as: Me” in deployment settings.

Error: “Script function not found: doGet”

Solution: Verify you pasted the complete script code and saved the project.

Balance not updating

Solution: The calculateBalance() function recalculates from all rows. Ensure your Amount (Column C) contains valid numbers.

AI features not working

Solution:
  1. Verify your GEMINI_KEY is set in Script Properties
  2. Check that your Gemini API key is valid and has quota remaining
  3. Review execution logs: Executions tab in Apps Script editor

Security Considerations

The Web App is set to “Anyone can access”. This means anyone with the URL can access your data. Consider:
  • Keeping your Web App URL private
  • Implementing additional authentication in the script
  • Using Google’s built-in access controls

Next Steps

API Endpoints

Explore all available endpoints and actions

Frontend Integration

Connect your frontend to the API

Build docs developers (and LLMs) love