copilot_frontend
copilot_budget

Save Budget

Saves a complete budget to database and creates/updates contact in HubSpot.

This endpoint:

  1. Gets province name from database
  2. Updates commercial phone if provided and different from current
  3. Recalculates the budget using BudgetCalculatorService
  4. Creates/updates contact in HubSpot with client data
  5. Creates note in HubSpot deal with selected option details
  6. Saves budget in presup_presupuestos table
  7. Generates tokenized URL and updates HubSpot deal property

Protected Endpoint: Requires JWT authentication and 'ui_comercial' or 'admin' role

Args: request: SaveBudgetRequest with client data, calculation parameters, selected option, and optional commercial phone current_user: Current authenticated user db: Database session

Returns: SaveBudgetResponse with success status, budget ID, and HubSpot contact ID

Raises: ErrValidation: If user does not have comercial_id ErrNotFound: If province not found Exception: If HubSpot or database save fails

post/api/budget/save

Request body

selected_optioninteger nullable

ID/name of the selected budget option (e.g., 'Básica', 'Premium')

enviar_hubspotboolean

If True, send to HubSpot and set estado=3. If False, only save as draft (estado=2)

presupuesto_idinteger nullable

ID of existing budget to update directly (optional)

comercial_idinteger nullable

Override comercial ID. Admin use only: assigns budget to the specified comercial instead of the current user

guarda_opcion_cliente_testboolean

Test-only flag to control client option saving. In production, this is derived from enviar_hubspot

Response

Successful Response

successboolean required

Whether the save was successful

messagestring required

Success/error message

budget_idinteger nullable

ID of the created budget in database

hubspot_contact_idstring nullable

HubSpot contact ID (created or updated)

hubspot_warningstring nullable

Warning message if HubSpot operation partially failed (e.g., invalid property)

Changes

No recorded changes to this endpoint across all 1 revision of this API.