Files
grist-accounting/scripts/upload-attachment.sh
Bill Ballou a83f436a08 Split Attachment column into Invoice and Receipt fields
- Add separate Invoice and Receipt columns to Bills table for clearer
  document organization
- Update upload-attachment.sh to accept column parameter (defaults to
  Invoice, use Receipt for payment confirmations)
- Update all documentation examples and workflows
- Add receipt upload step to payment workflows
- Update validation checklist to verify both fields

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-04 21:11:04 -05:00

70 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
# upload-attachment.sh - Upload file and link to Grist record
# Usage: ./upload-attachment.sh <file> <table> <record_id> [token] [column]
#
# Examples:
# ./upload-attachment.sh invoice.pdf Bills 13 # defaults to Invoice column
# ./upload-attachment.sh invoice.pdf Bills 13 sess_abc123... # with token
# ./upload-attachment.sh receipt.pdf Bills 13 sess_abc123... Receipt # specify column
set -e
FILE="$1"
TABLE="$2"
RECORD_ID="$3"
TOKEN="$4"
COLUMN="${5:-Invoice}" # Default to Invoice column
if [[ -z "$FILE" || -z "$TABLE" || -z "$RECORD_ID" ]]; then
echo "Usage: $0 <file> <table> <record_id> [token] [column]"
echo ""
echo "Arguments:"
echo " file Path to file to upload"
echo " table Grist table name (e.g., Bills)"
echo " record_id Record ID to attach file to"
echo " token Session token (optional, will prompt if not provided)"
echo " column Attachment column name (default: Invoice, use Receipt for payment receipts)"
echo ""
echo "Examples:"
echo " $0 invoice.pdf Bills 13 # Upload invoice"
echo " $0 receipt.pdf Bills 13 \$TOKEN Receipt # Upload receipt"
exit 1
fi
# Get token if not provided
if [[ -z "$TOKEN" ]]; then
echo "Paste session token (from request_session_token MCP call):"
read -r TOKEN
fi
# Base URL for the grist-mcp proxy
BASE_URL="${GRIST_MCP_URL:-https://grist-mcp.bballou.com}"
# Upload attachment
echo "Uploading $FILE..."
RESPONSE=$(curl -s -X POST \
-H "Authorization: Bearer $TOKEN" \
-F "file=@$FILE" \
"$BASE_URL/api/v1/attachments")
# Extract attachment ID
ATTACHMENT_ID=$(echo "$RESPONSE" | jq -r '.data.attachment_id')
if [[ "$ATTACHMENT_ID" == "null" || -z "$ATTACHMENT_ID" ]]; then
echo "Upload failed: $RESPONSE"
exit 1
fi
echo "Uploaded: attachment_id=$ATTACHMENT_ID"
# Link to record via proxy
echo "Linking to $TABLE id=$RECORD_ID column=$COLUMN..."
LINK_RESPONSE=$(curl -s -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"method\": \"update_records\", \"table\": \"$TABLE\", \"records\": [{\"id\": $RECORD_ID, \"fields\": {\"$COLUMN\": [\"L\", $ATTACHMENT_ID]}}]}" \
"$BASE_URL/api/v1/proxy")
echo "$LINK_RESPONSE" | jq .
echo "Done! Attachment $ATTACHMENT_ID linked to $TABLE.$COLUMN record $RECORD_ID"