Formulas API¶
The Formulas API provides endpoints for creating, validating, and applying visual formula configurations using a graph-based builder.
Overview¶
CalcBridge's formula builder supports:
- Graph-Based Design: Visual node-and-edge formula construction
- Validation: Structural and dependency validation before execution
- Preview: Test formulas against real data before applying
- Versioning: Track formula changes with version history
- Dual Mode: Builder (visual) and Advanced (expression) modes
Endpoints¶
Validate Formula Graph¶
Validate a formula graph structure and dependencies.
Request Body¶
| Field | Type | Required | Description |
|---|---|---|---|
graph | FormulaGraph | Yes | Graph definition with nodes and edges |
input_schema | object | No | Expected input column schema |
Example Request¶
curl -X POST "https://api.calcbridge.io/api/v1/formulas/validate" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"graph": {
"version": "1.0",
"template_id": "custom",
"nodes": [
{"id": "n1", "type": "column_ref", "params": {"column": "par_value"}},
{"id": "n2", "type": "column_ref", "params": {"column": "price"}},
{"id": "n3", "type": "expression", "params": {"formula": "n1 * n2 / 100"}}
],
"edges": [
{"id": "e1", "source": {"nodeId": "n1", "port": "out"}, "target": {"nodeId": "n3", "port": "in1"}},
{"id": "e2", "source": {"nodeId": "n2", "port": "out"}, "target": {"nodeId": "n3", "port": "in2"}}
]
}
}'
Response¶
Preview Formula¶
Preview formula results against real workbook data.
Request Body¶
| Field | Type | Required | Description |
|---|---|---|---|
graph | FormulaGraph | Yes | Formula graph to preview |
workbook_id | string (UUID) | Yes | Workbook to use for preview |
sheet_id | string (UUID) | Yes | Sheet to use for preview |
sample_size | integer | No | Preview rows (default: 25, max: 200) |
Response¶
{
"sample_results": [
{"row": 1, "input": {"par_value": 5000000, "price": 98.5}, "output": 4925000.0},
{"row": 2, "input": {"par_value": 3000000, "price": 101.2}, "output": 3036000.0}
],
"total_rows": 150,
"preview_size": 25,
"compiled_formula": "[par_value] * [price] / 100"
}
List Formula Configs¶
List formula configurations for the current tenant.
Query Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
page | integer | 1 | Page number |
page_size | integer | 20 | Items per page (max 100) |
Create Formula Config¶
Create a new formula configuration.
Request Body¶
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Formula name (1-255 chars) |
description | string | No | Description (max 1000 chars) |
template_id | string | Yes | Template identifier |
graph | FormulaGraph | Yes | Graph definition |
input_schema | object | No | Input column schema |
output_schema | object | No | Output column schema |
mode | string | No | Mode: builder (default) or advanced |
status | string | No | Status: draft (default), active, archived |
Response (201 Created)¶
{
"id": "fc_abc123",
"name": "Market Value Calculator",
"description": "Calculates market value from par and price",
"template_id": "custom",
"graph": { "..." },
"mode": "builder",
"status": "draft",
"version_count": 1,
"current_version": "v1",
"created_at": "2026-01-25T10:30:00Z"
}
Get Formula Config¶
Get a specific formula configuration with details.
Create Formula Version¶
Create a new version of an existing formula.
Request Body¶
| Field | Type | Required | Description |
|---|---|---|---|
graph | FormulaGraph | Yes | Updated graph definition |
change_notes | string | No | Description of changes |
List Formula Runs¶
List execution history for a formula.
Apply Formula¶
Apply a formula version to a workbook sheet.
Request Body¶
| Field | Type | Required | Description |
|---|---|---|---|
version_id | string | Yes | Formula version to apply |
workbook_id | string (UUID) | Yes | Target workbook |
sheet_id | string (UUID) | Yes | Target sheet |
target_column | string | Yes | Column to write results (1-255 chars) |
output_mode | string | No | Mode: new (default) or overwrite |
Response¶
{
"run_id": "run_abc123",
"config_id": "fc_abc123",
"version_id": "v1",
"status": "processing",
"rows_affected": 0,
"started_at": "2026-01-25T10:30:00Z"
}
Graph Node Types¶
| Type | Description | Parameters |
|---|---|---|
column_ref | Reference to a data column | column: column name |
constant | Literal value | value: the constant |
lookup_exact | Exact value lookup | default: fallback value |
compare | Comparison operation | operator: eq, ne, lt, gt, lte, gte |
if | Conditional branch | Three input ports (condition, true, false) |
and / or | Logical operations | Variable input ports |
sum / concat | Aggregation | Variable input ports |
expression | Raw formula expression | formula: expression string |
Related Documentation¶
- Formula Config Models - Data model reference
- Formula Builder - Feature documentation
- Calculations API - Direct formula evaluation