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

# Create a widget session for embedding the connect flow



## OpenAPI

````yaml /api-reference/openapi.json post /api/widget/sessions
openapi: 3.0.3
info:
  title: Polymorfa WhatsApp API
  version: 0.0.0
  description: >-
    Public Polymorfa REST API for sessions, messaging, media, webhooks,
    campaigns, templates, client tokens, widgets, and bridge routing.
  contact:
    name: Polymorfa API
    url: https://docs.polymorfa.com
servers:
  - url: https://api.polymorfa.com
security:
  - BearerAuth: []
paths:
  /api/widget/sessions:
    post:
      tags:
        - Widget
      summary: Create a widget session for embedding the connect flow
      operationId: createWidgetSession
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateWidgetSessionRequest'
      responses:
        '201':
          description: Widget session created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WidgetSessionResponseWrapper'
        '400':
          description: Bad request — request body or params failed validation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Missing or invalid authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Authenticated but not permitted (missing scope or rule violation)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Resource not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - BearerAuth: []
components:
  schemas:
    CreateWidgetSessionRequest:
      type: object
      properties:
        mode:
          type: string
          enum:
            - embedded
            - redirect
        projectId:
          type: string
        methods:
          type: array
          items:
            type: string
            enum:
              - qr
              - pairing
              - cloud-api
        businessName:
          type: string
          minLength: 1
        historySync:
          type: string
          enum:
            - force_on
            - force_off
            - ask
        sessionName:
          type: string
        callbackUrl:
          type: string
          format: uri
        allowedOrigins:
          type: array
          items:
            type: string
            format: uri
        theme:
          type: string
          enum:
            - light
            - dark
            - system
        accent:
          type: string
          pattern: ^#[0-9a-fA-F]{6}$
        prefillPhone:
          type: string
          pattern: ^\+?\d{6,15}$
        autoSubmitPhone:
          type: boolean
        analytics:
          type: object
          properties:
            posthogKey:
              type: string
            posthogHost:
              type: string
          required:
            - posthogKey
        metaApp:
          type: object
          properties:
            appId:
              type: string
              minLength: 1
            appSecret:
              type: string
              minLength: 1
          required:
            - appId
            - appSecret
    WidgetSessionResponseWrapper:
      type: object
      properties:
        success:
          type: boolean
          enum:
            - true
        data:
          $ref: '#/components/schemas/WidgetSessionResponse'
      required:
        - success
        - data
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error message
        docs:
          type: string
          description: URL to the documentation for this error
      required:
        - error
    WidgetSessionResponse:
      type: object
      properties:
        widgetUrl:
          type: string
        redirectUrl:
          type: string
        clientToken:
          type: string
        session:
          type: string
      required:
        - widgetUrl
        - redirectUrl
        - clientToken
        - session
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Polymorfa organization key (titan_ prefix), project token (titan_pt_
        prefix), or client token (titan_ct_ prefix), where the operation permits
        that audience.

````