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:| Column | Name | Type | Description |
|---|---|---|---|
| A | Date | Date | Transaction timestamp |
| B | Description | String | Transaction description |
| C | Amount | Number | Transaction amount |
| D | Category | String | Category (Food, Transport, Tech, Invest, Income, Misc) |
| E | Type | String | CREDIT or DEBIT |
The first row should contain headers. The script automatically skips the header row when processing data.
Deployment Steps
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
Get Your Sheet ID
Copy your Google Sheet ID from the URL:The Sheet ID is the long string between
/d/ and /edit.Open Apps Script Editor
In your Google Sheet, go to:Extensions → Apps ScriptThis opens the Google Apps Script editor in a new tab.
Paste the Script Code
Delete any existing code in the editor and paste the entire Google Apps Script code.
Save the Project
Click the save icon or press
Ctrl+S (Windows) / Cmd+S (Mac).Name your project (e.g., “SpendWisely George Backend”).Deploy as Web App
- Click Deploy → New deployment
- Click the gear icon next to “Select type” and choose Web app
- Configure the deployment:
- Description: “SpendWisely George API”
- Execute as: Me (your Google account)
- Who has access: Anyone
- Click Deploy
Authorize the Script
Google will ask you to authorize the script:
- Click Authorize access
- Select your Google account
- Click Advanced if you see a warning
- Click Go to [Project Name] (unsafe)
- Click Allow
Copy the Web App URL
After deployment, you’ll see a Web app URL. It looks like:
Copy this URL - you’ll need it to configure the frontend application.
Configure Script Properties (Optional)
To set up AI features and default settings:
- In the Apps Script editor, click Project Settings (gear icon)
- Scroll to Script Properties
- Click Add script property and add:
GEMINI_KEY: Your Gemini API keyDAILY_BUDGET: Default daily budget (e.g., “350”)PRIVACY_MODE: “true” or “false” (defaults to true)
Configuration Variables
Sheet ID
google_script.js:14
Script Properties
The following properties are stored usingPropertiesService.getScriptProperties():
Your Google Gemini API key for AI-powered features
Default daily budget amount
Enable/disable privacy mode (“true” or “false”)
Testing Your Deployment
Test your deployment using curl or Postman:Updating Your Deployment
When you make changes to the script:- Save your changes in the Apps Script editor
- Click Deploy → Manage deployments
- Click the edit icon (pencil) next to your active deployment
- Update the Version to “New version”
- Click Deploy
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: ThecalculateBalance() function recalculates from all rows. Ensure your Amount (Column C) contains valid numbers.
AI features not working
Solution:- Verify your
GEMINI_KEYis set in Script Properties - Check that your Gemini API key is valid and has quota remaining
- Review execution logs: Executions tab in Apps Script editor
Security Considerations
Next Steps
API Endpoints
Explore all available endpoints and actions
Frontend Integration
Connect your frontend to the API