# CALCULATORS

calculators endpoints.

**Base URL:** `https://api.trustpager.com/functions/v1/api/v1`

## Endpoints

### POST /calculators

Create a calculator as a draft. Give it inputs, rate tables and results (definition), try it with try_calculator, then publish_calculator to make it live. Gifts, quizzes, website calculators, client portals and opportunities use the live version.

**Scopes:** `calculators:write` — [full detail](./calculators/post-calculators.md)

### DELETE /calculators/:calculator_id

Delete a calculator no gift or quiz uses. One with saved runs needs confirm_runs: true, because its runs are deleted from their opportunities too.

**Scopes:** `calculators:delete` — [full detail](./calculators/delete-calculators-calculator-id.md)

### GET /calculators/:calculator_id

Get one calculator: its draft (inputs, rate tables, results) with draft_problems to fix before publishing, the live version's definition, its opportunity settings and where it is used.

**Scopes:** `calculators:read` — [full detail](./calculators/get-calculators-calculator-id.md)

### GET /calculators/:calculator_id/versions/:version

One published version of a calculator, exactly as it went live (inputs, rate tables, results).

**Scopes:** `calculators:read` — [full detail](./calculators/get-calculators-calculator-id-versions-version.md)

### GET /opportunity-calculators/:opportunity_id

The Calculators card of one opportunity: each calculator shown on it (switched on for opportunities, on its workflow), with its headline results, its latest saved run, how many runs it has, and start_answers (what a new team run starts from: the last answers, blanks filled from the opportunity's fields). Needs opportunities:read.

**Scopes:** `calculators:read` — [full detail](./calculators/get-opportunity-calculators-opportunity-id.md)

### GET /calculators/:calculator_id/runs

Saved runs of a calculator, newest first: version, where it came from (portal, website, team, automation, api), the answers and the results. Runs on opportunities show with opportunities:read and runs for a contact alone with contacts:read, only for records you can see. Filter with opportunity_id; limit up to 100.

**Scopes:** `calculators:read` — [full detail](./calculators/get-calculators-calculator-id-runs.md)

### GET /calculators/:calculator_id/versions

Every published version of a calculator, newest first: who published it, when, its notes, whether it is live, and how many runs used it.

**Scopes:** `calculators:read` — [full detail](./calculators/get-calculators-calculator-id-versions.md)

### GET /calculators

List the workspace's calculators, newest change first: status (draft: never published; live; live_with_draft_changes), live_version, how many inputs and results, how it shows on opportunities, and where it is used (gifts, quizzes, runs in the last 30 days). Filters: search, on_opportunities=true, limit, offset.

**Scopes:** `calculators:read` — [full detail](./calculators/get-calculators.md)

### POST /calculators/:calculator_id/publish

Publish the draft as the next version: it goes live at once everywhere the calculator is used, and every gift and quiz that uses it (update_gift / update_quiz calculator_id) follows it. Refused while the draft has problems, when nothing changed, or when a gift or quiz that uses it would break (each is named, with what to fix). Runs already saved keep the version they used, so their figures never change.

**Scopes:** `calculators:write` — [full detail](./calculators/post-calculators-calculator-id-publish.md)

### POST /calculators/:calculator_id/runs

Run a calculator with the live version and save the run, usually onto an opportunity (opportunity_id, needs opportunities:write) where its Calculators card shows it; for a contact only (contact_id) it needs contacts:write, and on neither, calculators:write. The figures are always worked out here from the answers; send answers only. Refused when an answer is wrong or the calculator is set not to save runs from automations and the API.

**Scopes:** `calculators:read` — [full detail](./calculators/post-calculators-calculator-id-runs.md)

### POST /calculators/:calculator_id/try

Work a calculator out with sample answers. Nothing is saved and nothing is charged. Tries the draft unless use is live; definition tries one not saved yet; opportunity_id starts from that opportunity's answers (its last run, then the opportunity fields set in opportunity.prefill, the same start a team run uses; answers sent win) (the "try the draft on a real opportunity" check before publishing).

**Scopes:** `calculators:read` — [full detail](./calculators/post-calculators-calculator-id-try.md)

### PATCH /calculators/:calculator_id

Change a calculator: name, description, its draft (definition replaces the whole draft; the live version does not change until publish_calculator) and how it shows on opportunities (opportunity merges). Showing it on opportunities needs a published version.

**Scopes:** `calculators:write` — [full detail](./calculators/patch-calculators-calculator-id.md)
