Skip to Content
Recodocs

Sales workspace API

Console routes for manual sales workspace operations—leads, intake, scoring, strategy, budget, and background operations.

7 min read

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.

MethodPathPermissionHandlerWhat it does
GET/scorersales.readscorer_statusReturns paginated scorer status via sales_scorer.status.
GET/scorer/cohortsales.readscorer_cohortReturns current scorer cohort projection.
GET/scorer/leads/{key}sales.readscorer_leadReturns paginated scorer detail for one lead key.
POST/scorer/profile/previewsales.writescorer_profile_previewPreviews a scorer profile change.
POST/scorer/profile/activatesales.writescorer_profile_approveCalls sales_scorer.profile_approve with a ProfileApprove body.
POST/scorer/authorizesales.writescorer_authorizeSets manifest.authorizing_actor to identity.principal from _admin() before sales_scorer.authorize.
POST/scorer/evaluatesales.writescorer_evaluateRuns scorer evaluate (host ingress console_background_operation).
POST/scorer/feedbacksales.writescorer_feedbackRecords scorer feedback.
POST/scorer/acceptsales.writescorer_acceptCalls sales_scorer.accept with an Accept body.
POST/scorer/releasesales.writescorer_releaseCalls sales_scorer.release with a Release body.
POST/scorer/reconcilesales.writescorer_reconcileCalls sales_scorer.reconcile with a GenerationCommand body.
GET/ (prefix root)sales.readworkspaceReturns domain.workspace under data, with optional query flag include_progress defaulting to false.
GET/spendingsales.readspendingReturns spending summary plus budgets and connects_ledger rows.
GET/scoressales.readscoresReads lead scores; entries with an active sales_score operation for the caller are marked refreshing or running.
GET/strategysales.readstrategyReads strategy for a month query parameter.
GET/analyticssales.readanalyticsReads analytics for a month query parameter.
GET/strategy/documentssales.readstrategy_documentsLists strategy documents.
POST/strategy/documentssales.writestrategy_document_commandRuns a strategy document command.
POST/strategysales.writesave_strategySaves strategy from request body.
GET/intakesales.readintakeReturns mail reception snapshot.
POST/intake/settingssales.writeintake_settingsConfigures reception enabled flag.
POST/intake/scansales.writeintake_scanEnqueues sales_mail_reception job; returns pending outcome.
POST/intake/{key}/decisionsales.writeintake_decisionApplies intake decision or submits background operation (host ingress on route).
POST/leads/{key}/scoresales.writescoreSubmits background operation sales_score unless sales_scorer.mode is active, which raises HTTP 409 manifest_required.
POST/budgetsales.writesave_budgetSaves budget from BudgetRequest.
GET/leads/{key}sales.readdetailReturns lead detail for key.
POST/adoptsales.writeadoptAdopts a lead; merges linear_sync with state pending into outcome.
POST/leadssales.writecreateSubmits sales_create background operation (host ingress).
POST/leads/{key}/updatessales.writeupdateRecords lead update; adds linear_sync local or pending by update kind.
POST/leads/{key}/syncsales.writesyncRequests Linear sync for the lead.
POST/purchasessales.writepurchaseLinks a purchase to the workspace.
GET/operations/{key}sales.readoperation_statusReads one background operation for the actor.
POST/operations/{key}/retrysales.writeretry_operationRetries 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

RouteParameterType / constraint
scorer_status, scorer_leadoffsetint, default 0, ge=0
scorer_status, scorer_leadlimitint, default 50, ge=1, le=100
scorer_lead, detail, sync, update, score, intake_decisionkeystr path segment
workspaceinclude_progressbool, default False
strategy, analyticsmonthstr, pattern `^20\d2-(0[1-9]
operation_status, retry_operationkeystr 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.

HandlerBody type
scorer_profile_previewscorer_contract.ProfilePreview
scorer_profile_approvescorer_contract.ProfileApprove
scorer_authorizescorer_contract.Authorize
scorer_evaluatescorer_contract.Evaluate
scorer_feedbackscorer_contract.FeedbackCommand
scorer_acceptscorer_contract.Accept
scorer_releasescorer_contract.Release
scorer_reconcilescorer_contract.GenerationCommand
strategy_document_commandsales_strategy_documents.DocumentCommand
save_strategysales_strategy.StrategyRequest
intake_settingssales_mail_reception.ReceptionSetting
intake_decisionsales_mail_reception.ReceptionDecision
scoresales_scoring.ScoreRequest
save_budgetBudgetRequest
adoptAdoptRequest
createCreateRequest
updateUpdateRequest
purchasePurchaseRequest

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

HandlerExtra response detail
spendingdata merges spending dict with budgets and connects_ledger keys.
scoresFor 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_scanoutcome: {"state": "pending", "job_name": "sales_mail_reception"}.
adoptoutcome includes nested linear_sync: {"state": "pending"}.
updatelinear_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:

ExceptionStatusCode
background_operations.OperationUnavailable503unavailable
background_operations.OperationConflict409conflict
sales_scorer.ScorerConflict409conflict
domain.SalesWorkspaceConflict409conflict
ValueError400invalid
LinearSyncError502provider_unavailable

Route-specific behaviour

  • score: If sales_scorer.mode(db) == "active", raises 409 with error_body("manifest_required", "Review an exact reassessment manifest first") before submit.
  • intake_scan: Enqueues a job with signal_key prefixed sales-scan:, job_name sales_mail_reception, trigger_kind domain, cause_type operator_scan, cause_ref actor, 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