Integration Scripts

Sync Revenue Data to HubSpot CRM

The Script

#!/bin/bash
# sync-revenue-to-hubspot.sh

HUBSPOT_API_KEY="your-hubspot-api-key"
START_DATE="2026-01-01"
END_DATE="2026-01-31"

# Get revenue by client for the period
kick transactions list \
  --from="$START_DATE" \
  --to="$END_DATE" \
  --filter="amount>0" \
  --format=json | \
jq -r '
  group_by(.counterparty) |
  map({
    client: .[0].counterparty,
    revenue: (map(.amount) | add)
  }) |
  .[]
' | while IFS= read -r line; do
  client=$(echo "$line" | jq -r '.client')
  revenue=$(echo "$line" | jq -r '.revenue')
  
  echo "Updating HubSpot for $client: $revenue"
  
  # Update HubSpot company property
  curl -X PATCH "https://api.hubapi.com/crm/v3/objects/companies/search" \
    -H "Authorization: Bearer $HUBSPOT_API_KEY" \
    -H "Content-Type: application/json" \
    -d "{
      \"properties\": {
        \"monthly_revenue\": \"$revenue\",
        \"last_revenue_update\": \"$(date -I)\"
      }
    }"
done

echo "βœ“ HubSpot revenue data updated"

How to Customize

  • Change date range to match your reporting period

  • Update different CRM fields (ARR, MRR, etc.)

  • Add error handling and retry logic

  • Filter by specific revenue categories

What It Outputs

  • Updates revenue fields in HubSpot for each client

  • Console output shows which clients were updated

Export to Data Warehouse

The Script

#!/bin/bash
# export-to-warehouse.sh

DB_HOST="your-db-host"
DB_NAME="analytics"
DB_USER="etl_user"

kick transactions list \
  --from="2026-01-01" \
  --format=json \
  > /tmp/kick-transactions.json

cat /tmp/kick-transactions.json | jq -r '
  .[] |
  [.id, .date, .amount, .counterparty, .category // "null"] |
  @csv
' | psql -h "$DB_HOST" -U "$DB_USER" -d "$DB_NAME" -c "
  COPY transactions (id, date, amount, counterparty, category)
  FROM STDIN WITH CSV
"

echo "βœ“ Transactions loaded to warehouse"

How to Customize

  • Add incremental loading

  • Transform data before loading

  • Schedule as part of nightly ETL

What It Outputs

  • Loads data into database table

  • Console confirmation

Export Project Expenses to Notion

The Script

#!/bin/bash
# export-to-notion.sh

NOTION_API_KEY="your-notion-api-key"
DATABASE_ID="your-notion-database-id"
PROJECT_NAME="Q1 Marketing Campaign"

# Get expenses for a specific project (by category or class)
kick transactions list \
  --from="2026-01-01" \
  --to="2026-03-31" \
  --filter="class=$PROJECT_NAME AND amount<0" \
  --format=json | \
jq -r '.[] | @json' | while IFS= read -r txn; do
  date=$(echo "$txn" | jq -r '.date')
  amount=$(echo "$txn" | jq -r '.amount | fabs')
  category=$(echo "$txn" | jq -r '.category')
  counterparty=$(echo "$txn" | jq -r '.counterparty')
  memo=$(echo "$txn" | jq -r '.memo // ""')
  
  echo "Adding $counterparty ($amount) to Notion"
  
  curl -X POST "https://api.notion.com/v1/pages" \
    -H "Authorization: Bearer $NOTION_API_KEY" \
    -H "Content-Type: application/json" \
    -H "Notion-Version: 2022-06-28" \
    -d "{
      \"parent\": { \"database_id\": \"$DATABASE_ID\" },
      \"properties\": {
        \"Date\": { \"date\": { \"start\": \"$date\" } },
        \"Vendor\": { \"title\": [{ \"text\": { \"content\": \"$counterparty\" } }] },
        \"Category\": { \"select\": { \"name\": \"$category\" } },
        \"Amount\": { \"number\": $amount },
        \"Notes\": { \"rich_text\": [{ \"text\": { \"content\": \"$memo\" } }] }
      }
    }"
done

echo "βœ“ Project expenses exported to Notion"

How to Customize

  • Change project identifier (class, category, or tag)

  • Map to different Notion properties

  • Add budget tracking formulas

  • Export to different Notion databases per project

What It Outputs

  • Creates a Notion page for each project expense

  • Console output shows which expenses were added

Send Weekly Expense Summary to Slack

The Script

#!/bin/bash
# weekly-expense-summary.sh

WEBHOOK_URL="https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK"
CHANNEL="#finance"

START_DATE="$(date -d 'last monday' +%Y-%m-%d)"
END_DATE="$(date -d 'last sunday' +%Y-%m-%d)"

# Get total expenses for the week
total=$(kick transactions list \
  --from="$START_DATE" \
  --to="$END_DATE" \
  --filter="amount<0" \
  --format=json | jq '[.[].amount] | add | fabs')

# Get top 3 expense categories
top_categories=$(kick transactions list \
  --from="$START_DATE" \
  --to="$END_DATE" \
  --filter="amount<0" \
  --format=json | \
jq -r '
  group_by(.category) |
  map({
    category: .[0].category // "Uncategorized",
    total: (map(.amount | fabs) | add)
  }) |
  sort_by(.total) | reverse | .[0:3] |
  map("β€’ \(.category): $\(.total)") |
  join("\n")
')

message="πŸ“Š *Weekly Expense Summary*\n*Week of $START_DATE*\n\n*Total Expenses:* \$$total\n\n*Top Categories:*\n$top_categories\n\n<https://app.kick.co/transactions|View Details>"

curl -X POST "$WEBHOOK_URL" \
  -H 'Content-Type: application/json' \
  -d "{
    \"channel\": \"$CHANNEL\",
    \"text\": \"$message\"
  }"

echo "βœ“ Weekly summary sent to Slack"

How to Customize

  • Change time period (daily, monthly)

  • Add budget comparisons

  • Include revenue summary

  • Send to different channels per entity

What It Outputs

Slack message:

πŸ“Š Weekly Expense Summary
Week of 2026-01-13

Total Expenses: $15,234.50

Top Categories:
- Payroll: $8,500.00
- Cloud Infrastructure: $2,100.00
- Marketing: $1,850.00

View Details

Last updated

Was this helpful?