> ## 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.

# Python build-complete callback

> Called by the Python workflow service when a sage build finishes
(success or failure).

**On success:** deducts credits from council ledger, advances sage
to step 5, clears build flags, and sends a completion email.

**On failure:** rolls back sage to step 3 and clears build flags
so the user can retry.

Requires the `X-API-Key` header matching the stored
`sage_screen_api_key` option.




## OpenAPI

````yaml /openapi/private/specs/wp/wp-webhooks.yml post /callback/build-complete
openapi: 3.1.0
info:
  title: >-
    SageScreen — Webhooks & CRM Integrations (Billing · Council · User · Deal ·
    Sage)
  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: Billing – Stripe
    description: Stripe webhook and subscription endpoints
  - name: Billing – Broadcast
    description: Postmark broadcast unsubscribe endpoint
  - name: Billing – Pipedrive
    description: Pipedrive CRM ID set-* webhook endpoints (called by Zapier)
  - name: Billing – AJAX
    description: Credit ledger, reactivation, and portal AJAX endpoints
  - name: Council – REST
    description: Zapier-facing REST endpoints for council data sync
  - name: Council – AJAX
    description: Council user and sage management AJAX endpoints
  - name: User – REST
    description: Zapier-facing REST endpoints
  - name: User – AJAX
    description: Council user management AJAX endpoints
  - name: User – Profile
    description: Self-service profile updates
  - name: Deal REST
    description: REST API endpoints authenticated via X-API-Key
  - name: Deal AJAX
    description: AJAX endpoints authenticated via WordPress nonce + capability check
  - name: Sage – REST
    description: REST API endpoints for sage operations and Python callbacks
  - name: Sage – CRUD
    description: AJAX endpoints for sage creation, editing, and status management
  - name: Sage – Build Workflow
    description: AJAX endpoints for the multi-step sage build process
paths:
  /callback/build-complete:
    post:
      tags:
        - Sage – REST
      summary: Python build-complete callback
      description: |
        Called by the Python workflow service when a sage build finishes
        (success or failure).

        **On success:** deducts credits from council ledger, advances sage
        to step 5, clears build flags, and sends a completion email.

        **On failure:** rolls back sage to step 3 and clears build flags
        so the user can retry.

        Requires the `X-API-Key` header matching the stored
        `sage_screen_api_key` option.
      operationId: restBuildCompleteCallback
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BuildCompleteRequest'
            examples:
              success:
                summary: Successful build
                value:
                  council_sage_id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                  status: success
              failed:
                summary: Failed build
                value:
                  council_sage_id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                  status: failed
      responses:
        '200':
          description: Callback processed successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BuildCompleteResponse'
              examples:
                success:
                  summary: Build success processed
                  value:
                    success: true
                    message: Sage build completed successfully
                    sage_id: 1234
                failed:
                  summary: Build failure processed
                  value:
                    success: true
                    message: Sage build failure recorded, rolled back to step 3
                    sage_id: 1234
        '400':
          description: Missing required parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SagePublicWPError'
              example:
                code: missing_param
                message: council_sage_id is required
                data:
                  status: 400
        '401':
          description: Missing or invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SagePublicWPError'
              examples:
                missing:
                  summary: No X-API-Key header
                  value:
                    code: invalid_api_key
                    message: Missing API key
                    data:
                      status: 401
                invalid:
                  summary: Key does not match
                  value:
                    code: invalid_api_key
                    message: Invalid API key
                    data:
                      status: 401
        '402':
          description: Insufficient credits to complete build
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SagePublicWPError'
              example:
                code: insufficient_credits
                message: Insufficient credits to complete sage build
                data:
                  status: 402
        '404':
          description: Council sage not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SagePublicWPError'
              example:
                code: sage_not_found
                message: >-
                  No council sage found with UUID:
                  a1b2c3d4-e5f6-7890-abcd-ef1234567890
                data:
                  status: 404
        '500':
          description: API key not configured on server
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SagePublicWPError'
              example:
                code: api_not_configured
                message: API key not configured
                data:
                  status: 500
      security:
        - apiKey: []
components:
  schemas:
    BuildCompleteRequest:
      type: object
      required:
        - council_sage_id
        - status
      properties:
        council_sage_id:
          type: string
          format: uuid
          description: Python council_sage UUID
          examples:
            - a1b2c3d4-e5f6-7890-abcd-ef1234567890
        status:
          type: string
          enum:
            - success
            - failed
          description: Build completion status
          examples:
            - success
    BuildCompleteResponse:
      type: object
      properties:
        success:
          type: boolean
          examples:
            - true
        message:
          type: string
          examples:
            - Sage build completed successfully
        sage_id:
          type: integer
          description: WordPress post ID of the updated sage
          examples:
            - 1234
    SagePublicWPError:
      type: object
      description: Standard WordPress REST API error envelope
      required:
        - code
        - message
        - data
      properties:
        code:
          type: string
          description: Machine-readable error code
          examples:
            - missing_param
        message:
          type: string
          description: Human-readable error message
          examples:
            - council_sage_id is required
        data:
          type: object
          required:
            - status
          properties:
            status:
              type: integer
              description: HTTP status code
              examples:
                - 400
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: X-API-Key
      description: SageScreen API key stored in `ss_zapier_api_key` option

````