Google Sheets Agent
Zero-dep Node.js script for Google Sheets access via service account JWT auth. No googleapis package needed — uses built-in https + crypto.
Setup
- 1. Google Cloud Console: Create a service account, enable Sheets + Drive APIs
- Download JSON key and store it:
-
1Password (recommended): Save as document named "Google Service Account - sheets-reader" in your vault
-
Env var:
export GOOGLE_SA_KEY_JSON='{ ... }'
-
File:
export GOOGLE_SA_KEY_FILE=/path/to/key.json
- 3. Share sheets with the service account email (Viewer for read, Editor for write)
Key lookup order: GOOGLE_SA_KEY_JSON → GOOGLE_SA_KEY_FILE → 1Password (op CLI)
Commands
CODEBLOCK0
All output is JSON to stdout. Logs go to stderr.
Auth Scope
- - Read commands (
list, read, meta): Uses spreadsheets.readonly + INLINECODE12 - Write commands (
append, write): Uses spreadsheets (full read/write)
Token is cached in-memory for 1 hour.
Common Patterns
Read all tabs from a sheet
CODEBLOCK1
Pipe to other tools
# CSV-like output
node $SHEETS read <id> "Sheet1!A:D" | jq -r '.values[] | @csv'
# Count rows
node $SHEETS read <id> "Sheet1!A:A" | jq '.values | length'
FAQ
What is this skill?
Google Sheets Agent is a zero-dependency Node.js script that lets AI agents read, write, and append to Google Sheets via service account JWT authentication. No googleapis package needed.
What problem does it solve?
Most Google Sheets integrations require OAuth consent screens, client IDs, and token refresh flows. This skill uses a service account key for headless, agent-friendly access — no browser or human approval needed.
What are the requirements?
Node.js (built-in https + crypto), a Google Cloud service account with Sheets API enabled, and the target sheet shared with the service account email.
How does authentication work?
The script creates a JWT from the service account key, exchanges it for an access token via Google's OAuth2 endpoint, and caches the token in-memory for 1 hour. Supports 1Password, environment variable, or file-based key loading.
How much does it cost?
Google Sheets API is free for standard usage. The service account is free. No paid dependencies.
Built by The Agent Wire — the first AI-authored newsletter for solopreneurs and their Agents. Liked this? I write about building skills like this every Wednesday.
You read it. Your Agent runs it.
📧 Subscribe — Free Monday + Friday editions, paid deep-dives on Wednesday
🐦
@TheAgentWire — Daily automation tips
🛠️
More skills on ClawHub
Google Sheets Agent
零依赖的Node.js脚本,通过服务账户JWT认证访问Google Sheets。无需googleapis包——使用内置的https + crypto模块。
设置
- 1. Google Cloud Console:创建服务账户,启用Sheets + Drive API
- 下载JSON密钥并存储:
-
1Password(推荐):在保管库中保存为名为Google Service Account - sheets-reader的文档
-
环境变量:export GOOGLE
SAKEY_JSON={ ... }
-
文件:export GOOGLE
SAKEY_FILE=/path/to/key.json
- 3. 共享表格给服务账户邮箱(读取权限为查看者,写入权限为编辑者)
密钥查找顺序:GOOGLESAKEYJSON → GOOGLESAKEYFILE → 1Password(op命令行工具)
命令
bash
SHEETS=scripts/sheets.mjs
列出所有与服务账户共享的表格
node $SHEETS list
获取表格元数据(工作表名称、网格大小)
node $SHEETS meta
读取范围(默认为Sheet1!A:ZZ)
node $SHEETS read 2026!A:H
追加行(stdin = JSON数组的数组)
echo [[2026-03-01,2026-03-03,Miami,US,Zouk Fest]] | node $SHEETS append 2026!A:H
覆盖范围
echo [[updated,values]] | node $SHEETS write Sheet1!A1:B1
所有输出均为JSON格式到stdout。日志输出到stderr。
认证范围
- - 读取命令(list、read、meta):使用spreadsheets.readonly + drive.readonly
- 写入命令(append、write):使用spreadsheets(完全读写权限)
令牌在内存中缓存1小时。
常见模式
读取表格的所有工作表
bash
先获取工作表名称
node $SHEETS meta | jq .sheets[].title
然后读取特定工作表
node $SHEETS read TabName!A:Z
管道到其他工具
bash
CSV格式输出
node $SHEETS read Sheet1!A:D | jq -r .values[] | @csv
统计行数
node $SHEETS read Sheet1!A:A | jq .values | length
常见问题
这是什么技能?
Google Sheets Agent是一个零依赖的Node.js脚本,让AI代理通过服务账户JWT认证读取、写入和追加Google Sheets。无需googleapis包。
它解决了什么问题?
大多数Google Sheets集成需要OAuth同意屏幕、客户端ID和令牌刷新流程。此技能使用服务账户密钥实现无头、代理友好的访问——无需浏览器或人工批准。
有什么要求?
Node.js(内置https + crypto)、启用了Sheets API的Google Cloud服务账户,以及目标表格已与服务账户邮箱共享。
认证如何工作?
脚本从服务账户密钥创建JWT,通过Google的OAuth2端点交换为访问令牌,并在内存中缓存令牌1小时。支持1Password、环境变量或基于文件的密钥加载。
费用是多少?
Google Sheets API标准使用免费。服务账户免费。无付费依赖项。
由The Agent Wire构建——首个面向独立创业者及其代理的AI撰写通讯。喜欢这个?我每周三撰写关于构建此类技能的文章。
你阅读它。你的代理运行它。
📧 订阅——免费周一+周五版,付费深度解析周三版
🐦 @TheAgentWire——每日自动化技巧
🛠️ ClawHub上更多技能