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

# Connect via QR code

> Get the QR code to connect the session to WhatsApp.

After creating an `unofficial` session, connect it by scanning the QR code with
WhatsApp on your phone (**Linked devices → Link a device**).

Use `?image=1` to receive the QR directly as a **PNG image**. Without the
parameter, the response contains the QR data as JSON, ideal for rendering the
code in your own front end.

> [!NOTE]
>
> The QR code expires within seconds and is renewed automatically. Call the endpoint
> again to get an updated code while the session is not connected.

> [!NOTE]
>
> A session that spends **45 minutes** generating QR codes without being connected, and without
> any calls to this endpoint, is hibernated and fires the
> [`connection.status` webhook with `qrcode_timeout`](https://docs.d-api.cloud/en/whatsapp/webhooks/conexao).
> The next call wakes the session up: it responds with `expired: true` and the new QR
> appears within a few seconds.


## OpenAPI

````yaml api-reference/openapi.en.json GET /api/v1/sessions/{sessionId}/qr
openapi: 3.1.0
info:
  title: D-API - Complete WhatsApp Infrastructure
  description: >-
    A scalable, robust solution for automation managers, SaaS products and end
    users who need a reliable WhatsApp integration. It offers multiple
    simultaneous instances, real-time webhooks, an intuitive dashboard and a
    documented REST API with 99.9% uptime and latency under 30ms.
  version: 1.2.1
  contact:
    name: Suporte D-API
    email: suporte@d-api.cloud
    url: https://d-api.cloud
servers:
  - url: https://api.d-api.cloud
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Home
    description: Base endpoints
  - name: Sessions
    description: Endpoints for managing sessions
  - name: Messages
    description: Endpoints for sending messages
  - name: Cloud API
    description: >-
      WhatsApp Official API (Meta Cloud API): manual connection, template
      management (list/create/delete) and template sending.
  - name: IVR Calls
    description: 'Voice call dispatch (IVR): single or bulk, with audio or an IVR flow.'
  - name: SMS
    description: 'SMS sending: single or bulk.'
  - name: Commands
    description: >-
      Look up asynchronous commands (async: true) by the commandId returned when
      enqueued.
paths:
  /api/v1/sessions/{sessionId}/qr:
    get:
      tags:
        - Sessions
      summary: Get a session's QR code
      description: >-
        Returns a session's QR code data. Use ?image=1 to get the QR code
        directly as a PNG image.
      operationId: getApiV1SessionsBySessionIdQr
      parameters:
        - name: sessionId
          in: path
          required: true
          schema:
            type: string
          description: Session identifier
        - name: image
          in: query
          required: false
          schema:
            type: string
            enum:
              - '1'
          description: Set to "1" to return PNG image directly instead of JSON
      responses:
        '200':
          description: QR code data (JSON) or PNG image (when ?image=1)
          content:
            application/json:
              schema:
                type: object
                properties:
                  sessionId:
                    type: string
                    description: Session identifier
                  status:
                    type: string
                    description: Session connection status
                  qrCode:
                    type: string
                    description: Raw QR code text for WhatsApp connection
                  qrCodeImage:
                    type: string
                    description: Base64 data URL of QR code PNG image
                  qrCodeUpdatedAt:
                    type: string
                    format: date-time
                    description: Timestamp when QR code was last updated
                required:
                  - sessionId
                  - status
              example:
                sessionId: session123
                status: connecting
                qrCode: 2@ABC123DEF456...
                qrCodeImage: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...
                qrCodeUpdatedAt: '2024-01-15T10:30:00.000Z'
            image/png:
              schema:
                type: string
                format: binary
        '404':
          description: Session not found or QR code not available
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  sessionId:
                    type: string
                  code:
                    type: number
              examples:
                session-not-found:
                  summary: Session not found
                  value:
                    error: Session not found
                    sessionId: session123
                    code: 404
                qr-not-available:
                  summary: QR code not available
                  value:
                    error: QR code not available
                    sessionId: session123
                    code: 404
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  sessionId:
                    type: string
                  code:
                    type: number
              example:
                error: Failed to get QR code
                sessionId: session123
                code: 500
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: 'API Key for authentication. Format: <API_KEY>'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.