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

# Playground Drafts

> Return full draft subject+body for every lead in the batch.

Tenant-scope enforced via ``service.get_batch_drafts`` which calls
``_load_campaign_owned(campaign_id, user_id)`` before any row read.
A user who passes another user's batch_id gets a 404 because the
``campaign_id`` is ownership-checked first — the batch filter is only
applied WITHIN an authorized campaign scope.

Intended usage from the UI: fetched once when the batch reaches
terminal-all (overall pending+running == 0), and on explicit "refresh
drafts" actions. NOT called on the 2s poll loop — the status endpoint
returns ``has_draft`` + ``subject_preview`` for that surface.



## OpenAPI

````yaml https://api.bavlio.com/openapi.json get /api/v1/campaigns/{campaign_id}/playground/drafts
openapi: 3.1.0
info:
  title: Bavlio API
  description: >-
    Outreach automation API — lead enrichment, email campaigns, LinkedIn
    automation, and AI agent. Full docs at https://docs.bavlio.com.
  version: 1.0.0
servers: []
security: []
tags:
  - name: API Keys
    description: >-
      Create, list, and revoke API keys for programmatic access. JWT
      authentication required.
  - name: credits
    description: Credit balance, cost estimates, and transaction history.
  - name: campaigns
    description: Create, manage, launch, and monitor email campaigns.
  - name: campaign-personalization
    description: AI-powered email subject and body personalization for campaigns.
  - name: email-finder
    description: Find and verify email addresses for prospects.
  - name: email-verification
    description: Validate email addresses and prune invalid entries from datasets.
  - name: sender-profiles
    description: Manage sender identity profiles for outreach.
  - name: sender-profile-chat
    description: Interactive chat for building sender profiles.
  - name: templates
    description: Email template CRUD.
  - name: suppression
    description: Do-not-contact suppression list management.
  - name: datasets
    description: Lead dataset listing, download, and updates.
  - name: user-extractions
    description: Uploaded lead file management and processing.
  - name: enrichment-chat
    description: Interactive chat for data enrichment sessions.
  - name: enrichment-processing
    description: Batch lead enrichment processing.
  - name: File Upload (CSV/Excel)
    description: Upload and preview CSV/Excel lead files.
  - name: connected-accounts
    description: LinkedIn account connections via Unipile.
  - name: linkedin-content
    description: LinkedIn post creation, scheduling, and management.
  - name: linkedin-playground
    description: Direct LinkedIn actions (profile lookup, messaging, engagement).
  - name: bavimail-proxy
    description: BaviMail domain, alias, and email management.
  - name: agent
    description: Bavi AI agent chat with SSE streaming.
  - name: notifications
    description: Notification preferences and delivery.
  - name: referral
    description: Referral code management and stats.
  - name: feedback
    description: User feedback submission.
  - name: authentication
    description: JWT token verification and user info.
  - name: Google OAuth
    description: Google OAuth login flow and access tokens.
  - name: Google Sheets OAuth
    description: Google Sheets import and access management.
  - name: stripe
    description: Stripe checkout, billing portal, and subscription status. JWT only.
  - name: users
    description: User quota and usage information.
  - name: Health
    description: Health checks and system status.
  - name: Personalization
    description: Core lead personalization engine.
  - name: Session Management
    description: Enrichment session lifecycle.
  - name: Session Processing
    description: Session data processing.
  - name: webhooks
    description: Inbound webhook handlers (Stripe, BaviMail, Unipile).
paths:
  /api/v1/campaigns/{campaign_id}/playground/drafts:
    get:
      tags:
        - playground
      summary: Playground Drafts
      description: |-
        Return full draft subject+body for every lead in the batch.

        Tenant-scope enforced via ``service.get_batch_drafts`` which calls
        ``_load_campaign_owned(campaign_id, user_id)`` before any row read.
        A user who passes another user's batch_id gets a 404 because the
        ``campaign_id`` is ownership-checked first — the batch filter is only
        applied WITHIN an authorized campaign scope.

        Intended usage from the UI: fetched once when the batch reaches
        terminal-all (overall pending+running == 0), and on explicit "refresh
        drafts" actions. NOT called on the 2s poll loop — the status endpoint
        returns ``has_draft`` + ``subject_preview`` for that surface.
      operationId: playground_drafts_api_v1_campaigns__campaign_id__playground_drafts_get
      parameters:
        - name: campaign_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: Campaign Id
        - name: batch_id
          in: query
          required: true
          schema:
            type: string
            format: uuid
            description: Batch ID produced by POST /playground/generate.
            title: Batch Id
          description: Batch ID produced by POST /playground/generate.
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PlaygroundDraftsResponse'
        '401':
          description: Unauthorized
        '404':
          description: Campaign or lead not found
        '409':
          description: Concurrent edit conflict
        '422':
          description: Validation failure
      security:
        - HTTPBearer: []
components:
  schemas:
    PlaygroundDraftsResponse:
      properties:
        campaign_id:
          type: string
          format: uuid
          title: Campaign Id
        batch_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Batch Id
        drafts:
          items:
            $ref: '#/components/schemas/PlaygroundDraft'
          type: array
          title: Drafts
      type: object
      required:
        - campaign_id
      title: PlaygroundDraftsResponse
      description: >-
        Response model for `GET /campaigns/:id/playground/drafts?batch_id=...`.


        One-shot fetch — frontend calls this when the batch reaches terminal-all

        OR on explicit "refresh drafts" user action. Response size can
        legitimately

        be large (50 leads × 50KB body = 2.5MB) because it is user-initiated,
        not

        a polling endpoint.
    PlaygroundDraft:
      properties:
        campaign_lead_id:
          type: string
          format: uuid
          title: Campaign Lead Id
        subject:
          type: string
          maxLength: 500
          minLength: 1
          title: Subject
        body:
          type: string
          maxLength: 50000
          minLength: 1
          title: Body
        generated_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Generated At
        prompt_version_hash:
          anyOf:
            - type: string
            - type: 'null'
          title: Prompt Version Hash
      type: object
      required:
        - campaign_lead_id
        - subject
        - body
      title: PlaygroundDraft
      description: |-
        Full generated draft body for a single lead. Returned in a list from
        `GET /campaigns/:id/playground/drafts`. Bounds match the A1 approve
        limits so an approved body fits through the same validators.
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````