KosmoKrator

accounting

FreshBooks Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the FreshBooks KosmoKrator integration.

8 functions 7 read 1 write Bearer token auth

Lua Namespace

Agents call this integration through app.integrations.freshbooks.*. Use lua_read_doc("integrations.freshbooks") inside KosmoKrator to discover the same reference at runtime.

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

FreshBooks — Lua API Reference

list_invoices

List invoices from FreshBooks with optional filtering and pagination.

Parameters

NameTypeRequiredDescription
searchobjectnoSearch filters (see below)
pageintegernoPage number (default: 1)
per_pageintegernoResults per page (default: 15, max: 100)

Search Filter Keys

KeyDescription
statusInvoice status: draft, sent, viewed, paid, disputed, overdue
clientidFilter by client ID
date_fromStart date (YYYY-MM-DD)
date_toEnd date (YYYY-MM-DD)
invoice_numberFilter by invoice number

Example

local result = app.integrations.freshbooks.list_invoices({
  search = { status = "sent" },
  per_page = 25
})

for _, invoice in ipairs(result.invoices) do
  print(invoice.invoice_number .. ": " .. invoice.amount.amount .. " " .. invoice.status)
end

get_invoice

Get full details of a specific invoice.

Parameters

NameTypeRequiredDescription
invoice_idintegeryesThe FreshBooks invoice ID

Example

local result = app.integrations.freshbooks.get_invoice({ invoice_id = 12345 })
local inv = result.invoice
print(inv.invoice_number .. " - " .. inv.status)
for _, line in ipairs(inv.lines) do
  print("  " .. line.name .. ": " .. line.unit_cost.amount)
end

create_invoice

Create a new invoice in FreshBooks.

Parameters

NameTypeRequiredDescription
client_idintegeryesThe client ID to bill
linesarrayyesArray of line items (see below)
datestringnoInvoice date (YYYY-MM-DD), defaults to today
due_datestringnoDue date (YYYY-MM-DD)
invoice_numberstringnoCustom invoice number
notesstringnoNotes displayed on the invoice
termsstringnoPayment terms (e.g., “Net 30”)
discount_valuenumbernoDiscount amount or percentage
discount_typestringnopercentage or amount

Line Item Format

Each line item is an object with:

KeyTypeRequiredDescription
namestringyesLine item name
descriptionstringnoLine item description
qtynumberyesQuantity
unit_costobjectyesObject with amount (string) and code (currency code)

Example

local result = app.integrations.freshbooks.create_invoice({
  client_id = 100,
  lines = {
    {
      name = "Web Development",
      description = "Frontend development work",
      qty = 40,
      unit_cost = { amount = "150.00", code = "USD" }
    }
  },
  notes = "Thank you for your business!",
  terms = "Net 30"
})
print("Created invoice: " .. result.invoice.invoice_number)

list_clients

List clients from FreshBooks.

Parameters

NameTypeRequiredDescription
searchobjectnoSearch filters (see below)
pageintegernoPage number (default: 1)
per_pageintegernoResults per page (default: 15, max: 100)

Search Filter Keys

KeyDescription
emailFilter by email address
fnameFilter by first name
lnameFilter by last name
organizationFilter by organization name
stateactive or archived

Example

local result = app.integrations.freshbooks.list_clients({
  search = { organization = "Acme" },
  per_page = 50
})

for _, client in ipairs(result.clients) do
  print(client.organization .. " - " .. client.email)
end

get_client

Get details of a specific client.

Parameters

NameTypeRequiredDescription
client_idintegeryesThe FreshBooks client ID

Example

local result = app.integrations.freshbooks.get_client({ client_id = 100 })
local client = result.client
print(client.organization .. " - Balance: " .. client.outstanding_balance.amount)

list_projects

List projects from FreshBooks.

Parameters

NameTypeRequiredDescription
searchobjectnoSearch filters (see below)
pageintegernoPage number (default: 1)
per_pageintegernoResults per page (default: 15, max: 100)

Search Filter Keys

KeyDescription
titleFilter by project title
activetrue or false
clientidFilter by client ID

Example

local result = app.integrations.freshbooks.list_projects({
  search = { active = true }
})

for _, project in ipairs(result.projects) do
  print(project.title .. " - " .. project.billing_method)
end

list_payments

List payments from FreshBooks.

Parameters

NameTypeRequiredDescription
searchobjectnoSearch filters (see below)
pageintegernoPage number (default: 1)
per_pageintegernoResults per page (default: 15, max: 100)

Search Filter Keys

KeyDescription
clientidFilter by client ID
invoiceidFilter by invoice ID
date_fromStart date (YYYY-MM-DD)
date_toEnd date (YYYY-MM-DD)
typePayment type: check, credit, card, bank

Example

local result = app.integrations.freshbooks.list_payments({
  search = { date_from = "2025-01-01", date_to = "2025-01-31" },
  per_page = 50
})

for _, payment in ipairs(result.payments) do
  print(payment.date .. ": " .. payment.amount.amount .. " via " .. payment.type)
end

get_current_user

Get the profile of the currently authenticated FreshBooks user.

Parameters

None.

Example

local result = app.integrations.freshbooks.get_current_user({})

for _, user in ipairs(result.users) do
  print(user.first_name .. " " .. user.last_name .. " - " .. user.email)
end

Multi-Account Usage

If you have multiple FreshBooks accounts configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.freshbooks.function_name({...})

-- Explicit default (portable across setups)
app.integrations.freshbooks.default.function_name({...})

-- Named accounts
app.integrations.freshbooks.us_business.function_name({...})
app.integrations.freshbooks.eu_business.function_name({...})

All functions are identical across accounts — only the credentials differ.

Raw agent markdown
# FreshBooks — Lua API Reference

## list_invoices

List invoices from FreshBooks with optional filtering and pagination.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `search` | object | no | Search filters (see below) |
| `page` | integer | no | Page number (default: 1) |
| `per_page` | integer | no | Results per page (default: 15, max: 100) |

### Search Filter Keys

| Key | Description |
|-----|-------------|
| `status` | Invoice status: `draft`, `sent`, `viewed`, `paid`, `disputed`, `overdue` |
| `clientid` | Filter by client ID |
| `date_from` | Start date (YYYY-MM-DD) |
| `date_to` | End date (YYYY-MM-DD) |
| `invoice_number` | Filter by invoice number |

### Example

```lua
local result = app.integrations.freshbooks.list_invoices({
  search = { status = "sent" },
  per_page = 25
})

for _, invoice in ipairs(result.invoices) do
  print(invoice.invoice_number .. ": " .. invoice.amount.amount .. " " .. invoice.status)
end
```

---

## get_invoice

Get full details of a specific invoice.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `invoice_id` | integer | yes | The FreshBooks invoice ID |

### Example

```lua
local result = app.integrations.freshbooks.get_invoice({ invoice_id = 12345 })
local inv = result.invoice
print(inv.invoice_number .. " - " .. inv.status)
for _, line in ipairs(inv.lines) do
  print("  " .. line.name .. ": " .. line.unit_cost.amount)
end
```

---

## create_invoice

Create a new invoice in FreshBooks.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `client_id` | integer | yes | The client ID to bill |
| `lines` | array | yes | Array of line items (see below) |
| `date` | string | no | Invoice date (YYYY-MM-DD), defaults to today |
| `due_date` | string | no | Due date (YYYY-MM-DD) |
| `invoice_number` | string | no | Custom invoice number |
| `notes` | string | no | Notes displayed on the invoice |
| `terms` | string | no | Payment terms (e.g., "Net 30") |
| `discount_value` | number | no | Discount amount or percentage |
| `discount_type` | string | no | `percentage` or `amount` |

### Line Item Format

Each line item is an object with:

| Key | Type | Required | Description |
|-----|------|----------|-------------|
| `name` | string | yes | Line item name |
| `description` | string | no | Line item description |
| `qty` | number | yes | Quantity |
| `unit_cost` | object | yes | Object with `amount` (string) and `code` (currency code) |

### Example

```lua
local result = app.integrations.freshbooks.create_invoice({
  client_id = 100,
  lines = {
    {
      name = "Web Development",
      description = "Frontend development work",
      qty = 40,
      unit_cost = { amount = "150.00", code = "USD" }
    }
  },
  notes = "Thank you for your business!",
  terms = "Net 30"
})
print("Created invoice: " .. result.invoice.invoice_number)
```

---

## list_clients

List clients from FreshBooks.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `search` | object | no | Search filters (see below) |
| `page` | integer | no | Page number (default: 1) |
| `per_page` | integer | no | Results per page (default: 15, max: 100) |

### Search Filter Keys

| Key | Description |
|-----|-------------|
| `email` | Filter by email address |
| `fname` | Filter by first name |
| `lname` | Filter by last name |
| `organization` | Filter by organization name |
| `state` | `active` or `archived` |

### Example

```lua
local result = app.integrations.freshbooks.list_clients({
  search = { organization = "Acme" },
  per_page = 50
})

for _, client in ipairs(result.clients) do
  print(client.organization .. " - " .. client.email)
end
```

---

## get_client

Get details of a specific client.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `client_id` | integer | yes | The FreshBooks client ID |

### Example

```lua
local result = app.integrations.freshbooks.get_client({ client_id = 100 })
local client = result.client
print(client.organization .. " - Balance: " .. client.outstanding_balance.amount)
```

---

## list_projects

List projects from FreshBooks.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `search` | object | no | Search filters (see below) |
| `page` | integer | no | Page number (default: 1) |
| `per_page` | integer | no | Results per page (default: 15, max: 100) |

### Search Filter Keys

| Key | Description |
|-----|-------------|
| `title` | Filter by project title |
| `active` | `true` or `false` |
| `clientid` | Filter by client ID |

### Example

```lua
local result = app.integrations.freshbooks.list_projects({
  search = { active = true }
})

for _, project in ipairs(result.projects) do
  print(project.title .. " - " .. project.billing_method)
end
```

---

## list_payments

List payments from FreshBooks.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `search` | object | no | Search filters (see below) |
| `page` | integer | no | Page number (default: 1) |
| `per_page` | integer | no | Results per page (default: 15, max: 100) |

### Search Filter Keys

| Key | Description |
|-----|-------------|
| `clientid` | Filter by client ID |
| `invoiceid` | Filter by invoice ID |
| `date_from` | Start date (YYYY-MM-DD) |
| `date_to` | End date (YYYY-MM-DD) |
| `type` | Payment type: `check`, `credit`, `card`, `bank` |

### Example

```lua
local result = app.integrations.freshbooks.list_payments({
  search = { date_from = "2025-01-01", date_to = "2025-01-31" },
  per_page = 50
})

for _, payment in ipairs(result.payments) do
  print(payment.date .. ": " .. payment.amount.amount .. " via " .. payment.type)
end
```

---

## get_current_user

Get the profile of the currently authenticated FreshBooks user.

### Parameters

None.

### Example

```lua
local result = app.integrations.freshbooks.get_current_user({})

for _, user in ipairs(result.users) do
  print(user.first_name .. " " .. user.last_name .. " - " .. user.email)
end
```

---

## Multi-Account Usage

If you have multiple FreshBooks accounts configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.freshbooks.function_name({...})

-- Explicit default (portable across setups)
app.integrations.freshbooks.default.function_name({...})

-- Named accounts
app.integrations.freshbooks.us_business.function_name({...})
app.integrations.freshbooks.eu_business.function_name({...})
```

All functions are identical across accounts — only the credentials differ.

Metadata-Derived Lua Example

local result = app.integrations.freshbooks.freshbooks_list_invoices({
  search = "example_search",
  page = 1,
  per_page = 1
})
print(result)

Functions

freshbooks_list_invoices

List invoices from FreshBooks. Returns invoice details including status, amounts, client info, and dates. Supports filtering by status, client, date range, and more.

Operation
Read read
Full name
freshbooks.freshbooks_list_invoices
ParameterTypeRequiredDescription
search object no Search filters. Keys: status (e.g., "sent", "paid", "draft"), clientid, date_from, date_to, invoice_number. Pass as an object.
page integer no Page number for pagination (default: 1).
per_page integer no Results per page (default: 15, max: 100).

freshbooks_get_invoice

Get details of a specific FreshBooks invoice by ID. Returns full invoice data including line items, amounts, client details, status, and payment info.

Operation
Read read
Full name
freshbooks.freshbooks_get_invoice
ParameterTypeRequiredDescription
invoice_id integer yes The FreshBooks invoice ID.

freshbooks_create_invoice

Create a new invoice in FreshBooks. Requires at minimum a client ID and line items. Supports setting due date, notes, discount, and other invoice fields.

Operation
Write write
Full name
freshbooks.freshbooks_create_invoice
ParameterTypeRequiredDescription
client_id integer yes The client ID to bill.
lines array yes Array of line items. Each line should have: name (string), description (string, optional), qty (number), unit_cost (object with amount and code).
date string no Invoice date (YYYY-MM-DD). Defaults to today.
due_date string no Due date (YYYY-MM-DD). Optional.
invoice_number string no Custom invoice number. Auto-generated if omitted.
notes string no Notes displayed on the invoice.
terms string no Payment terms (e.g., "Net 30").
discount_value number no Discount amount or percentage.
discount_type string no Discount type: "percentage" or "amount".

freshbooks_list_clients

List clients from FreshBooks. Returns client details including name, email, company, and balance. Supports filtering and pagination.

Operation
Read read
Full name
freshbooks.freshbooks_list_clients
ParameterTypeRequiredDescription
search object no Search filters. Keys: email, fname, lname, organization, state (active/archived). Pass as an object.
page integer no Page number for pagination (default: 1).
per_page integer no Results per page (default: 15, max: 100).

freshbooks_get_client

Get details of a specific FreshBooks client by ID. Returns full client profile including contact info, company details, and outstanding balance.

Operation
Read read
Full name
freshbooks.freshbooks_get_client
ParameterTypeRequiredDescription
client_id integer yes The FreshBooks client ID.

freshbooks_list_projects

List projects from FreshBooks. Returns project details including title, description, billing method, budget, and active status. Supports filtering and pagination.

Operation
Read read
Full name
freshbooks.freshbooks_list_projects
ParameterTypeRequiredDescription
search object no Search filters. Keys: title, active (true/false), clientid. Pass as an object.
page integer no Page number for pagination (default: 1).
per_page integer no Results per page (default: 15, max: 100).

freshbooks_list_payments

List payments from FreshBooks. Returns payment details including amount, date, client, invoice, and payment method. Supports filtering and pagination.

Operation
Read read
Full name
freshbooks.freshbooks_list_payments
ParameterTypeRequiredDescription
search object no Search filters. Keys: clientid, invoiceid, date_from, date_to, type (check/credit/card/bank). Pass as an object.
page integer no Page number for pagination (default: 1).
per_page integer no Results per page (default: 15, max: 100).

freshbooks_get_current_user

Get the profile of the currently authenticated FreshBooks user. Returns user details including name, email, and linked business/member information. Useful for verifying connection and identity.

Operation
Read read
Full name
freshbooks.freshbooks_get_current_user
ParameterTypeRequiredDescription
No parameters.