Sales workspace API
Console routes for manual sales workspace operations—leads, intake, scoring, strategy, budget, and background operations.
The sales workspace API is an OS-admin and console-token protected surface for operating the manual Sales workspace from the console. Routes live under the /api/sales/workspace prefix. Read handlers return a data object; mutating handlers return an outcome object.
What this API area is for
The workspace API exposes the records used by a human-operated sales process. A successful read and the outcome of a mutation have different response contracts.
This module wires the console to sales domain services: workspace overview, lead lifecycle (create, adopt, detail, updates, sync, scoring), mail intake and decisions, monthly strategy and analytics, strategy documents, spending and budgets, purchases, scorer governance, and polling or retrying background operations. Most domain work runs through current_application().db and shared sales libraries; several commands enqueue or submit background operations instead of completing synchronously.
Routes
All paths are relative to /api/sales/workspace.
| Method | Path | Permission | Handler | What it does |
|---|---|---|---|---|
| GET | /scorer | sales.read | scorer_status | Returns paginated scorer status via sales_scorer.status. |
| GET | /scorer/cohort | sales.read | scorer_cohort | Returns current scorer cohort projection. |
| GET | /scorer/leads/{key} | sales.read | scorer_lead | Returns paginated scorer detail for one lead key. |
| POST | /scorer/profile/preview | sales.write | scorer_profile_preview | Previews a scorer profile change. |
| POST | /scorer/profile/activate | sales.write | scorer_profile_approve | Calls sales_scorer.profile_approve with a ProfileApprove body. |
| POST | /scorer/authorize | sales.write | scorer_authorize | Sets manifest.authorizing_actor to identity.principal from _admin() before sales_scorer.authorize. |
| POST | /scorer/evaluate | sales.write | scorer_evaluate | Runs scorer evaluate (host ingress console_background_operation). |
| POST | /scorer/feedback | sales.write | scorer_feedback | Records scorer feedback. |
| POST | /scorer/accept | sales.write | scorer_accept | Calls sales_scorer.accept with an Accept body. |
| POST | /scorer/release | sales.write | scorer_release | Calls sales_scorer.release with a Release body. |
| POST | /scorer/reconcile | sales.write | scorer_reconcile | Calls sales_scorer.reconcile with a GenerationCommand body. |
| GET | / (prefix root) | sales.read | workspace | Returns domain.workspace under data, with optional query flag include_progress defaulting to false. |
| GET | /spending | sales.read | spending | Returns spending summary plus budgets and connects_ledger rows. |
| GET | /scores | sales.read | scores | Reads lead scores; entries with an active sales_score operation for the caller are marked refreshing or running. |
| GET | /strategy | sales.read | strategy | Reads strategy for a month query parameter. |
| GET | /analytics | sales.read | analytics | Reads analytics for a month query parameter. |
| GET | /strategy/documents | sales.read | strategy_documents | Lists strategy documents. |
| POST | /strategy/documents | sales.write | strategy_document_command | Runs a strategy document command. |
| POST | /strategy | sales.write | save_strategy | Saves strategy from request body. |
| GET | /intake | sales.read | intake | Returns mail reception snapshot. |
| POST | /intake/settings | sales.write | intake_settings | Configures reception enabled flag. |
| POST | /intake/scan | sales.write | intake_scan | Enqueues sales_mail_reception job; returns pending outcome. |
| POST | /intake/{key}/decision | sales.write | intake_decision | Applies intake decision or submits background operation (host ingress on route). |
| POST | /leads/{key}/score | sales.write | score | Submits background operation sales_score unless sales_scorer.mode is active, which raises HTTP 409 manifest_required. |
| POST | /budget | sales.write | save_budget | Saves budget from BudgetRequest. |
| GET | /leads/{key} | sales.read | detail | Returns lead detail for key. |
| POST | /adopt | sales.write | adopt | Adopts a lead; merges linear_sync with state pending into outcome. |
| POST | /leads | sales.write | create | Submits sales_create background operation (host ingress). |
| POST | /leads/{key}/updates | sales.write | update | Records lead update; adds linear_sync local or pending by update kind. |
| POST | /leads/{key}/sync | sales.write | sync | Requests Linear sync for the lead. |
| POST | /purchases | sales.write | purchase | Links a purchase to the workspace. |
| GET | /operations/{key} | sales.read | operation_status | Reads one background operation for the actor. |
| POST | /operations/{key}/retry | sales.write | retry_operation | Retries a background operation. |
Request and response models
Handlers are typed to return dict[str, object]. Successful reads wrap the payload in data. Successful writes return outcome, including intake_settings; both intake_settings and intake_scan set that outcome without _call.
Query and path parameters
| Route | Parameter | Type / constraint |
|---|---|---|
| scorer_status, scorer_lead | offset | int, default 0, ge=0 |
| scorer_status, scorer_lead | limit | int, default 50, ge=1, le=100 |
| scorer_lead, detail, sync, update, score, intake_decision | key | str path segment |
| workspace | include_progress | bool, default False |
| strategy, analytics | month | str, pattern `^20\d2-(0[1-9] |
| operation_status, retry_operation | key | str operation key |
Request bodies (JSON)
Body types come from recox modules (sales_scorer_contract, sales_workspace_contract, sales_strategy, sales_strategy_documents, sales_mail_reception, sales_scoring); the route file defines no fields.
| Handler | Body type |
|---|---|
| scorer_profile_preview | scorer_contract.ProfilePreview |
| scorer_profile_approve | scorer_contract.ProfileApprove |
| scorer_authorize | scorer_contract.Authorize |
| scorer_evaluate | scorer_contract.Evaluate |
| scorer_feedback | scorer_contract.FeedbackCommand |
| scorer_accept | scorer_contract.Accept |
| scorer_release | scorer_contract.Release |
| scorer_reconcile | scorer_contract.GenerationCommand |
| strategy_document_command | sales_strategy_documents.DocumentCommand |
| save_strategy | sales_strategy.StrategyRequest |
| intake_settings | sales_mail_reception.ReceptionSetting |
| intake_decision | sales_mail_reception.ReceptionDecision |
| score | sales_scoring.ScoreRequest |
| save_budget | BudgetRequest |
| adopt | AdoptRequest |
| create | CreateRequest |
| update | UpdateRequest |
| purchase | PurchaseRequest |
scorer_authorize copies the body and sets manifest.authorizing_actor to the string returned by _admin() before calling the scorer.
On ignore, intake_decision calls sales_mail_reception.decide with secrets={}; otherwise it submits sales_intake_decision with JSON key and body.
score passes request_id from the body as str(body.request_id) to background submit, with payload fields key, request_id, and refresh.
create submits with resource_key and request_id of str(body.request_id) and payload=body.model_dump(mode="json").
Response shapes declared in handlers
| Handler | Extra response detail |
|---|---|
| spending | data merges spending dict with budgets and connects_ledger keys. |
| scores | For this actor's active sales_score resources, if the score exists and is not disabled, excluded, or incomplete, set refreshing when assessment is truthy; otherwise set state to running. |
| intake_scan | outcome: {"state": "pending", "job_name": "sales_mail_reception"}. |
| adopt | outcome includes nested linear_sync: {"state": "pending"}. |
| update | linear_sync.state is "local" when body.kind is one of content, content_package, hold, resume; otherwise "pending". |
| _scorer_write routes | {"outcome": ...} from the scorer operation. |
Behaviour and errors
Admin gate (_admin)
Every listed handler calls _admin() (directly or via _scorer_write). It reads principal.authorization_snapshot(). If enforcement_mode is local_unconfigured, or authorization.authorize(identity, "sales.write") is false, the handler raises HTTP 403 with error_body("denied", "Sales workspace requires admin access"). On success it returns identity.principal as the actor string used in downstream calls.
Console write trust
Every POST calls require_console_write_trust, but scorer_authorize calls _admin() and copies the manifest before that check.
_call exception mapping
Domain actions wrapped in _call map exceptions to HTTP errors with error_body codes:
| Exception | Status | Code |
|---|---|---|
background_operations.OperationUnavailable | 503 | unavailable |
background_operations.OperationConflict | 409 | conflict |
sales_scorer.ScorerConflict | 409 | conflict |
domain.SalesWorkspaceConflict | 409 | conflict |
ValueError | 400 | invalid |
LinearSyncError | 502 | provider_unavailable |
Route-specific behaviour
- score: If
sales_scorer.mode(db) == "active", raises 409 witherror_body("manifest_required", "Review an exact reassessment manifest first")before submit. - intake_scan: Enqueues a job with
signal_keyprefixedsales-scan:,job_namesales_mail_reception,trigger_kinddomain,cause_typeoperator_scan,cause_refactor, inside a DB transaction. - Routes decorated with
@host_ingress("console_background_operation"):scorer_evaluate,intake_decision,create,score.
FastAPI validates query constraints (offset, limit, month pattern) at the framework layer before handlers run.
How the permission model applies
The console maintains a route-to-permission table keyed as {module}.{handler_name} (for example sales_workspace_routes.workspace). Each entry is a ceiling: gate refuses signed-in users whose role does not hold that permission; capabilities or handlers may narrow further but not widen it. Unlisted endpoints block console startup via require_complete.
For this module, sales.read covers GET handlers and sales.write covers POST handlers, as registered in the route permission map. That table is separate from the in-handler _admin() check, which always requires the sales.write authorization grant ("Sales workspace requires admin access" on failure). Write POSTs also require console write trust via require_console_write_trust.
With sign-in off, the caller is Recohut's OS admin on this computer, and a bearer-authenticated machine call carries its own grants. With sign-in on, gate enforces the mapped sales.read or sales.write permission before the handler runs. _admin() is applied in addition to the gate and still refuses local_unconfigured enforcement.
How is this page?
Last updated on