KosmoKrator

logistics

Onfleet Lua API for KosmoKrator Agents

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

9 functions 6 read 3 write API key auth

Lua Namespace

Agents call this integration through app.integrations.onfleet.*. Use lua_read_doc("integrations.onfleet") 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.

Onfleet — Lua API Reference

list_tasks

List delivery tasks with optional filters.

Parameters

NameTypeRequiredDescription
stateintegernoTask state: 0=unassigned, 1=assigned, 2=active, 3=completed
workerstringnoFilter by worker ID
organizationstringnoFilter by organization ID
teamstringnoFilter by team ID
completeBeforeAfterstringnoISO 8601 — tasks completed after this time
completeBeforeBeforestringnoISO 8601 — tasks with completeBefore before this time
fromstringnoISO 8601 — tasks created after this time
tostringnoISO 8601 — tasks created before this time
lastUpdatedstringnoISO 8601 — tasks updated after this time
querystringnoSearch by recipient name, notes, or tracking URL

Task States

ValueDescription
0Unassigned
1Assigned
2Active (in-progress)
3Completed

Examples

List all unassigned tasks

local result = app.integrations.onfleet.list_tasks({
  state = 0
})

for _, task in ipairs(result.tasks) do
  print(task.id .. ": " .. task.destination.address.street)
end

List completed tasks for a worker

local result = app.integrations.onfleet.list_tasks({
  state = 3,
  worker = "WORKER_ID"
})

List tasks created today

local result = app.integrations.onfleet.list_tasks({
  from = "2026-04-05T00:00:00Z",
  to = "2026-04-05T23:59:59Z"
})

get_task

Get detailed information about a specific task.

Parameters

NameTypeRequiredDescription
task_idstringyesThe Onfleet task ID (24-char hex string)

Example

local result = app.integrations.onfleet.get_task({
  task_id = "TASK_ID"
})

print("Status: " .. result.state)
print("Destination: " .. result.destination.address.street)
print("Recipient: " .. result.recipients[1].name)

create_task

Create a new delivery task.

Parameters

NameTypeRequiredDescription
destination_addressstringyesDestination street address
recipient_namestringyesRecipient full name
recipient_phonestringnoRecipient phone (E.164 format)
recipient_emailstringnoRecipient email
notesstringnoDriver notes
complete_afterstringnoISO 8601 — earliest completion time
complete_beforestringnoISO 8601 — latest completion deadline
pickup_taskbooleannoTrue if this is a pickup (default: false)
workerstringnoWorker ID to assign
teamstringnoTeam ID to assign
quantityintegernoNumber of units
service_timeintegernoEstimated service time in seconds

Example

local result = app.integrations.onfleet.create_task({
  destination_address = "123 Main St, San Francisco, CA 94105",
  recipient_name = "Jane Doe",
  recipient_phone = "+14155551234",
  notes = "Leave at front door",
  complete_before = "2026-04-05T18:00:00Z",
  team = "TEAM_ID"
})

print("Created task: " .. result.task.id)

update_task

Update an existing task. Only provided fields are changed.

Parameters

NameTypeRequiredDescription
task_idstringyesTask ID to update
destination_addressstringnoNew destination address
notesstringnoUpdated driver notes
complete_afterstringnoUpdated earliest completion time (ISO 8601)
complete_beforestringnoUpdated latest completion deadline (ISO 8601)
workerstringnoNew worker ID (empty to unassign)
teamstringnoNew team ID
quantityintegernoUpdated quantity
service_timeintegernoUpdated service time in seconds

Example

local result = app.integrations.onfleet.update_task({
  task_id = "TASK_ID",
  notes = "Updated: ring doorbell twice",
  worker = "NEW_WORKER_ID"
})

delete_task

Delete a task permanently.

Parameters

NameTypeRequiredDescription
task_idstringyesTask ID to delete

Example

local result = app.integrations.onfleet.delete_task({
  task_id = "TASK_ID"
})

print(result) -- "Task 'TASK_ID' has been deleted."

list_workers

List all workers (drivers).

Parameters

NameTypeRequiredDescription
teamsarraynoArray of team IDs to filter by
statesarraynoWorker states: 0=off-duty, 1=on-duty
namestringnoFilter by name
phonestringnoFilter by phone
querystringnoGeneral search query

Example

local result = app.integrations.onfleet.list_workers({
  states = {1}
})

for _, worker in ipairs(result.workers) do
  print(worker.name .. " - " .. (worker.vehicle and worker.vehicle.description or "no vehicle"))
end

list_teams

List all teams in the organization.

Parameters

None.

Example

local result = app.integrations.onfleet.list_teams()

for _, team in ipairs(result) do
  print(team.name .. " (" .. #team.workers .. " workers)")
end

list_recipients

List recipients (delivery customers).

Parameters

NameTypeRequiredDescription
namestringnoFilter by name
phonestringnoFilter by phone
emailstringnoFilter by email
querystringnoGeneral search query

Example

local result = app.integrations.onfleet.list_recipients({
  name = "Jane"
})

for _, recipient in ipairs(result) do
  print(recipient.name .. " - " .. (recipient.phone or "no phone"))
end

get_current_user

Get the currently authenticated Onfleet user profile.

Parameters

None.

Example

local result = app.integrations.onfleet.get_current_user()

print("Logged in as: " .. result.email)
print("Organization: " .. result.organization)

Multi-Account Usage

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

-- Default account (always works)
app.integrations.onfleet.list_tasks({state = 0})

-- Explicit default (portable across setups)
app.integrations.onfleet.default.list_tasks({state = 0})

-- Named accounts
app.integrations.onfleet.us_fleet.list_tasks({})
app.integrations.onfleet.eu_fleet.list_tasks({})

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

Raw agent markdown
# Onfleet — Lua API Reference

## list_tasks

List delivery tasks with optional filters.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `state` | integer | no | Task state: 0=unassigned, 1=assigned, 2=active, 3=completed |
| `worker` | string | no | Filter by worker ID |
| `organization` | string | no | Filter by organization ID |
| `team` | string | no | Filter by team ID |
| `completeBeforeAfter` | string | no | ISO 8601 — tasks completed after this time |
| `completeBeforeBefore` | string | no | ISO 8601 — tasks with completeBefore before this time |
| `from` | string | no | ISO 8601 — tasks created after this time |
| `to` | string | no | ISO 8601 — tasks created before this time |
| `lastUpdated` | string | no | ISO 8601 — tasks updated after this time |
| `query` | string | no | Search by recipient name, notes, or tracking URL |

### Task States

| Value | Description |
|-------|-------------|
| 0 | Unassigned |
| 1 | Assigned |
| 2 | Active (in-progress) |
| 3 | Completed |

### Examples

#### List all unassigned tasks

```lua
local result = app.integrations.onfleet.list_tasks({
  state = 0
})

for _, task in ipairs(result.tasks) do
  print(task.id .. ": " .. task.destination.address.street)
end
```

#### List completed tasks for a worker

```lua
local result = app.integrations.onfleet.list_tasks({
  state = 3,
  worker = "WORKER_ID"
})
```

#### List tasks created today

```lua
local result = app.integrations.onfleet.list_tasks({
  from = "2026-04-05T00:00:00Z",
  to = "2026-04-05T23:59:59Z"
})
```

---

## get_task

Get detailed information about a specific task.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `task_id` | string | yes | The Onfleet task ID (24-char hex string) |

### Example

```lua
local result = app.integrations.onfleet.get_task({
  task_id = "TASK_ID"
})

print("Status: " .. result.state)
print("Destination: " .. result.destination.address.street)
print("Recipient: " .. result.recipients[1].name)
```

---

## create_task

Create a new delivery task.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `destination_address` | string | yes | Destination street address |
| `recipient_name` | string | yes | Recipient full name |
| `recipient_phone` | string | no | Recipient phone (E.164 format) |
| `recipient_email` | string | no | Recipient email |
| `notes` | string | no | Driver notes |
| `complete_after` | string | no | ISO 8601 — earliest completion time |
| `complete_before` | string | no | ISO 8601 — latest completion deadline |
| `pickup_task` | boolean | no | True if this is a pickup (default: false) |
| `worker` | string | no | Worker ID to assign |
| `team` | string | no | Team ID to assign |
| `quantity` | integer | no | Number of units |
| `service_time` | integer | no | Estimated service time in seconds |

### Example

```lua
local result = app.integrations.onfleet.create_task({
  destination_address = "123 Main St, San Francisco, CA 94105",
  recipient_name = "Jane Doe",
  recipient_phone = "+14155551234",
  notes = "Leave at front door",
  complete_before = "2026-04-05T18:00:00Z",
  team = "TEAM_ID"
})

print("Created task: " .. result.task.id)
```

---

## update_task

Update an existing task. Only provided fields are changed.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `task_id` | string | yes | Task ID to update |
| `destination_address` | string | no | New destination address |
| `notes` | string | no | Updated driver notes |
| `complete_after` | string | no | Updated earliest completion time (ISO 8601) |
| `complete_before` | string | no | Updated latest completion deadline (ISO 8601) |
| `worker` | string | no | New worker ID (empty to unassign) |
| `team` | string | no | New team ID |
| `quantity` | integer | no | Updated quantity |
| `service_time` | integer | no | Updated service time in seconds |

### Example

```lua
local result = app.integrations.onfleet.update_task({
  task_id = "TASK_ID",
  notes = "Updated: ring doorbell twice",
  worker = "NEW_WORKER_ID"
})
```

---

## delete_task

Delete a task permanently.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `task_id` | string | yes | Task ID to delete |

### Example

```lua
local result = app.integrations.onfleet.delete_task({
  task_id = "TASK_ID"
})

print(result) -- "Task 'TASK_ID' has been deleted."
```

---

## list_workers

List all workers (drivers).

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `teams` | array | no | Array of team IDs to filter by |
| `states` | array | no | Worker states: 0=off-duty, 1=on-duty |
| `name` | string | no | Filter by name |
| `phone` | string | no | Filter by phone |
| `query` | string | no | General search query |

### Example

```lua
local result = app.integrations.onfleet.list_workers({
  states = {1}
})

for _, worker in ipairs(result.workers) do
  print(worker.name .. " - " .. (worker.vehicle and worker.vehicle.description or "no vehicle"))
end
```

---

## list_teams

List all teams in the organization.

### Parameters

None.

### Example

```lua
local result = app.integrations.onfleet.list_teams()

for _, team in ipairs(result) do
  print(team.name .. " (" .. #team.workers .. " workers)")
end
```

---

## list_recipients

List recipients (delivery customers).

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `name` | string | no | Filter by name |
| `phone` | string | no | Filter by phone |
| `email` | string | no | Filter by email |
| `query` | string | no | General search query |

### Example

```lua
local result = app.integrations.onfleet.list_recipients({
  name = "Jane"
})

for _, recipient in ipairs(result) do
  print(recipient.name .. " - " .. (recipient.phone or "no phone"))
end
```

---

## get_current_user

Get the currently authenticated Onfleet user profile.

### Parameters

None.

### Example

```lua
local result = app.integrations.onfleet.get_current_user()

print("Logged in as: " .. result.email)
print("Organization: " .. result.organization)
```

---

## Multi-Account Usage

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

```lua
-- Default account (always works)
app.integrations.onfleet.list_tasks({state = 0})

-- Explicit default (portable across setups)
app.integrations.onfleet.default.list_tasks({state = 0})

-- Named accounts
app.integrations.onfleet.us_fleet.list_tasks({})
app.integrations.onfleet.eu_fleet.list_tasks({})
```

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

Metadata-Derived Lua Example

local result = app.integrations.onfleet.onfleet_list_tasks({
  state = 1,
  worker = "example_worker",
  organization = "example_organization",
  team = "example_team",
  completeBeforeAfter = "example_completeBeforeAfter",
  completeBeforeBefore = "example_completeBeforeBefore",
  from = "example_from",
  to = "example_to"
})
print(result)

Functions

onfleet_list_tasks

List delivery tasks from Onfleet. Filter by state (0=unassigned, 1=assigned, 2=active, 3=completed), worker, team, or time range. Returns task details including destination, recipient, and completion status.

Operation
Read read
Full name
onfleet.onfleet_list_tasks
ParameterTypeRequiredDescription
state integer no Task state filter: 0=unassigned, 1=assigned, 2=active, 3=completed.
worker string no Filter tasks assigned to a specific worker ID.
organization string no Filter tasks by organization ID.
team string no Filter tasks by team ID.
completeBeforeAfter string no ISO 8601 timestamp — list tasks completed after this time.
completeBeforeBefore string no ISO 8601 timestamp — list tasks with completeBefore before this time.
from string no ISO 8601 timestamp — list tasks created after this time.
to string no ISO 8601 timestamp — list tasks created before this time.
lastUpdated string no ISO 8601 timestamp — list tasks updated after this time.
query string no Search query to filter tasks by recipient name, notes, or tracking URL.

onfleet_get_task

Get detailed information about a specific delivery task by its ID. Returns destination, recipient, worker assignment, completion details, and tracking info.

Operation
Read read
Full name
onfleet.onfleet_get_task
ParameterTypeRequiredDescription
task_id string yes The Onfleet task ID (24-character hex string).

onfleet_create_task

Create a new delivery task in Onfleet. Requires a destination address and recipient details. Optionally assign to a worker or team, set time windows, and add notes.

Operation
Write write
Full name
onfleet.onfleet_create_task
ParameterTypeRequiredDescription
destination_address string yes Destination street address (e.g., "123 Main St, San Francisco, CA 94105").
destination_address_unparsed string no Full unparsed address string if you prefer Onfleet to geocode it.
recipient_name string yes Recipient full name.
recipient_phone string no Recipient phone number (E.164 format preferred).
recipient_email string no Recipient email address.
notes string no Notes for the driver about the task.
complete_after string no ISO 8601 timestamp — earliest time task can be completed.
complete_before string no ISO 8601 timestamp — latest time task must be completed by.
pickup_task boolean no Set to true if this is a pickup task instead of a dropoff.
worker string no Worker ID to directly assign the task to.
team string no Team ID to assign the task to (for auto-dispatch).
merchant string no Merchant/organization ID for the task.
executor string no Organization ID of the executor (for interconnected fleets).
quantity integer no Number of units for the task.
service_time integer no Estimated service time in seconds.
appearance array no Visual customization: {"triangleColor": "#RRGGBB"}.
metadata array no Custom metadata array: [{"name": "key", "value": "val", "visibility": ["worker"]}].

onfleet_update_task

Update an existing delivery task in Onfleet. Only the fields you provide will be changed. You can update destination, assignment, notes, time windows, and more.

Operation
Write write
Full name
onfleet.onfleet_update_task
ParameterTypeRequiredDescription
task_id string yes The Onfleet task ID to update (24-character hex string).
destination_address string no New destination address.
notes string no Updated driver notes.
complete_after string no ISO 8601 timestamp — earliest completion time.
complete_before string no ISO 8601 timestamp — latest completion deadline.
worker string no Worker ID to assign (pass null or empty to unassign).
team string no Team ID to assign to.
quantity integer no Updated quantity.
service_time integer no Updated estimated service time in seconds.
appearance array no Visual customization: {"triangleColor": "#RRGGBB"}.
metadata array no Updated custom metadata.

onfleet_delete_task

Delete a delivery task from Onfleet. Only unassigned or unsuccessfully completed tasks can be deleted. This action is permanent.

Operation
Write write
Full name
onfleet.onfleet_delete_task
ParameterTypeRequiredDescription
task_id string yes The Onfleet task ID to delete (24-character hex string).

onfleet_list_workers

List all workers (drivers) in Onfleet. Optionally filter by team or worker state. Returns worker name, phone, vehicle details, and current status.

Operation
Read read
Full name
onfleet.onfleet_list_workers
ParameterTypeRequiredDescription
teams array no Array of team IDs to filter workers by.
states array no Array of worker states to filter by: 0=off-duty, 1=on-duty.
name string no Filter workers by name.
phone string no Filter workers by phone number.
query string no General search query for workers.

onfleet_list_teams

List all teams in your Onfleet organization. Returns team name, manager, assigned workers, and hub location.

Operation
Read read
Full name
onfleet.onfleet_list_teams
ParameterTypeRequiredDescription
No parameters.

onfleet_list_recipients

List recipients (delivery customers) from Onfleet. Search by name, phone, or email. Returns recipient contact details.

Operation
Read read
Full name
onfleet.onfleet_list_recipients
ParameterTypeRequiredDescription
name string no Filter recipients by name.
phone string no Filter recipients by phone number.
email string no Filter recipients by email address.
query string no General search query for recipients.

onfleet_get_current_user

Get the currently authenticated Onfleet user profile. Returns name, email, organization, and account details. Useful for verifying API connectivity.

Operation
Read read
Full name
onfleet.onfleet_get_current_user
ParameterTypeRequiredDescription
No parameters.