> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sagescreen.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Mark deal as lost

> Marks a deal as `ss_lost` with a categorized reason and optional notes.
Records the previous status for possible restoration. Fires the `lost`
webhook with reason and notes in the payload.

Status guard: cannot mark as lost if already `ss_paid`, `ss_closed`, or
already `ss_lost`.

**Nonce:** `sagescreen_frontend_nonce`
**Capability:** `ss_sales` or `ss_sales_admin` or `ss_admin_all`




## OpenAPI

````yaml /openapi/private/specs/wp/deal-internal.yml post /wp-admin/admin-ajax.php?action=sagescreen_mark_deal_lost
openapi: 3.1.0
info:
  title: SageScreen — Deal Module
  description: >
    Enterprise deal lifecycle management. Deals represent sales proposals that

    flow through a multi-stage approval and payment pipeline before provisioning

    a council.


    **CPT:** `ss_deal`

    **Custom statuses:** `draft`, `ss_pending_approval`, `ss_approved`,

    `ss_customer_sent`, `ss_customer_approved`, `ss_customer_rejected`,

    `ss_invoiced`, `ss_paid`, `ss_closed`, `ss_lost`


    **Business rule:** Only Enterprise (E-SKU) products go through the
    deal/sales

    process. Packs and subscriptions are not sold via deals. Trials are
    Stripe-only.
  version: 1.0.0
servers:
  - url: https://{domain}/wp-json/sagescreen/v1
    description: WordPress REST API
    variables:
      domain:
        default: api.sagescreen.app
security: []
tags:
  - name: Deal REST
    description: REST API endpoints authenticated via X-API-Key
  - name: Deal AJAX
    description: AJAX endpoints authenticated via WordPress nonce + capability check
paths:
  /wp-admin/admin-ajax.php?action=sagescreen_mark_deal_lost:
    post:
      tags:
        - Deal AJAX
      summary: Mark deal as lost
      description: |
        Marks a deal as `ss_lost` with a categorized reason and optional notes.
        Records the previous status for possible restoration. Fires the `lost`
        webhook with reason and notes in the payload.

        Status guard: cannot mark as lost if already `ss_paid`, `ss_closed`, or
        already `ss_lost`.

        **Nonce:** `sagescreen_frontend_nonce`
        **Capability:** `ss_sales` or `ss_sales_admin` or `ss_admin_all`
      operationId: ajaxMarkDealLost
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              required:
                - nonce
                - action
                - deal_id
                - loss_reason
              properties:
                nonce:
                  type: string
                  examples:
                    - abc123def456
                action:
                  type: string
                  const: sagescreen_mark_deal_lost
                deal_id:
                  type: integer
                  examples:
                    - 1042
                loss_reason:
                  $ref: '#/components/schemas/LossReason'
                loss_notes:
                  type: string
                  description: Optional additional notes
                  examples:
                    - Customer chose CompetitorX due to existing relationship
      responses:
        '200':
          description: Deal marked as lost
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AjaxSuccessWithDealId'
              example:
                success: true
                data:
                  message: Deal marked as lost
                  deal_id: 1042
        '400':
          description: Bad request or status guard violation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AjaxErrorResponse'
              examples:
                missingReason:
                  summary: No loss reason provided
                  value:
                    success: false
                    data:
                      message: A loss reason is required
                alreadyLost:
                  summary: Deal is already lost
                  value:
                    success: false
                    data:
                      message: Deal is already marked as lost
                paidOrClosed:
                  summary: Cannot mark paid/closed deal as lost
                  value:
                    success: false
                    data:
                      message: Cannot mark a paid or closed deal as lost
        '403':
          $ref: '#/components/responses/AjaxForbidden'
      security:
        - wpAjaxNonce: []
components:
  schemas:
    LossReason:
      type: string
      enum:
        - price_was_too_high
        - opted_for_a_competitor
        - junk_lead
        - not_interested
        - client_requirement_not_met
      description: Categorized loss reason for `sagescreen_mark_deal_lost`
    AjaxSuccessWithDealId:
      type: object
      properties:
        success:
          type: boolean
          const: true
        data:
          type: object
          properties:
            message:
              type: string
              examples:
                - Deal saved successfully
            deal_id:
              type: integer
              examples:
                - 1042
    AjaxErrorResponse:
      type: object
      description: WordPress AJAX error envelope (wp_send_json_error)
      required:
        - success
        - data
      properties:
        success:
          type: boolean
          const: false
        data:
          oneOf:
            - type: object
              properties:
                message:
                  type: string
                  description: Human-readable error message
                  examples:
                    - Deal not found
                errors:
                  type: array
                  description: Validation error list (submit_deal only)
                  items:
                    type: string
                  examples:
                    - - Customer name is required
                      - Contact email is required
                redirect_edit:
                  type: boolean
                  description: Whether front end should redirect to edit form
                  examples:
                    - true
                edit_url:
                  type: string
                  description: URL to redirect to for fixing validation errors
                  examples:
                    - /admin/sales/calc?deal=1042
            - type: string
              description: Simple error message string
              examples:
                - Deal not found
  responses:
    AjaxForbidden:
      description: User does not have the required capability
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AjaxErrorResponse'
          example:
            success: false
            data:
              message: You do not have permission to perform this action
  securitySchemes:
    wpAjaxNonce:
      type: apiKey
      in: query
      name: nonce
      description: |
        WordPress AJAX nonce — either `sagescreen_frontend_nonce` or
        `sagescreen_sales_calc` depending on the endpoint (see each endpoint
        description). Sent as a form field in the POST body.

````