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

# Claim Connected Account

> Free a LinkedIn slug previously connected by another user.

The frontend calls this after receiving a 409 ``account_owned_by_another_user``
from /connect or /connect-cookie. That earlier 409 carries a signed
``claim_token`` AND deletes the requesting user's freshly minted
Unipile account upstream so no orphan accumulates if the user never
follows through. Presenting the token here:

1. Verifies HMAC + expiry + requesting-user binding (fail-closed).
2. Enforces single-use jti via INSERT into ``consumed_claim_tokens``;
   a replay returns 410 Gone.
3. Runs the DB function ``claim_connected_account`` which (inside one
   transaction) disconnects the previous owner's row, pauses their
   campaigns, and queues a user_alert.
4. Best-effort: deletes the previous owner's Unipile account upstream.

The function does NOT INSERT a new row for the requesting user.
Response carries ``next_action="reconnect"``; the frontend redirects
the user back to /connect (or /connect-cookie) to register their own
Unipile session, which now succeeds because the slug is no longer
held by any connected row.



## OpenAPI

````yaml https://api.bavlio.com/openapi.json post /api/v1/connected-accounts/claim
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/connected-accounts/claim:
    post:
      tags:
        - connected-accounts
      summary: Claim Connected Account
      description: >-
        Free a LinkedIn slug previously connected by another user.


        The frontend calls this after receiving a 409
        ``account_owned_by_another_user``

        from /connect or /connect-cookie. That earlier 409 carries a signed

        ``claim_token`` AND deletes the requesting user's freshly minted

        Unipile account upstream so no orphan accumulates if the user never

        follows through. Presenting the token here:


        1. Verifies HMAC + expiry + requesting-user binding (fail-closed).

        2. Enforces single-use jti via INSERT into ``consumed_claim_tokens``;
           a replay returns 410 Gone.
        3. Runs the DB function ``claim_connected_account`` which (inside one
           transaction) disconnects the previous owner's row, pauses their
           campaigns, and queues a user_alert.
        4. Best-effort: deletes the previous owner's Unipile account upstream.


        The function does NOT INSERT a new row for the requesting user.

        Response carries ``next_action="reconnect"``; the frontend redirects

        the user back to /connect (or /connect-cookie) to register their own

        Unipile session, which now succeeds because the slug is no longer

        held by any connected row.
      operationId: claim_connected_account_api_v1_connected_accounts_claim_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClaimRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClaimResponse'
        '401':
          description: Unauthorized
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    ClaimRequest:
      properties:
        claim_token:
          type: string
          maxLength: 4096
          minLength: 10
          title: Claim Token
      type: object
      required:
        - claim_token
      title: ClaimRequest
      description: Request body for ``POST /api/v1/connected-accounts/claim``.
    ClaimResponse:
      properties:
        success:
          type: boolean
          title: Success
          default: true
        previous_owner_user_id:
          type: string
          format: uuid
          title: Previous Owner User Id
          description: User ID of the previous owner (for client-side audit logging only).
        linkedin_slug:
          type: string
          title: Linkedin Slug
          description: >-
            The canonical slug that was freed. The frontend uses this to prompt
            the user to re-run /connect and complete onboarding.
        next_action:
          type: string
          title: Next Action
          description: >-
            Always 'reconnect'. The frontend should redirect the user back to
            the connect flow so they can register their own Unipile session.
          default: reconnect
      type: object
      required:
        - previous_owner_user_id
        - linkedin_slug
      title: ClaimResponse
      description: |-
        Response from a successful ownership transfer.

        The claim flow only DISCONNECTS the previous owner's row to free
        the canonical slug; the requesting user re-runs ``/connect`` to
        register their own Unipile session, which then succeeds because
        the slug is no longer held.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````