# Integration Scripts

<details>

<summary><strong>Sync Revenue Data to HubSpot CRM</strong></summary>

**The Script**

bash

```bash
#!/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

</details>

<details>

<summary><strong>Export to Data Warehouse</strong></summary>

**The Script**

bash

```bash
#!/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

</details>

<details>

<summary><strong>Export Project Expenses to Notion</strong></summary>

**The Script**

bash

```bash
#!/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

</details>

<details>

<summary><strong>Send Weekly Expense Summary to Slack</strong></summary>

**The Script**

bash

```bash
#!/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
```

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kick.co/ai/kick-cli/cli-use-case-library/integration-scripts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
