GET /instance/connect/:instanceName
Connect a WhatsApp instance to the WhatsApp servers. For Baileys integration, this generates a QR code that you scan with WhatsApp mobile app. For already connected instances, this returns the current connection state.Authentication
This endpoint requires authentication via theapikey header.
Path Parameters
Name of the instance you want to connect. This is the
instanceName you specified when creating the instance.Query Parameters
WhatsApp phone number to connect (optional). Used for pairing with phone number instead of QR code.
Response
The response varies based on the current connection state:Already Connected (state: open)
Connecting (state: connecting)
Raw QR code string
QR code as base64-encoded image. Display this in an
<img> tag or QR code reader.Pairing code for phone number authentication (when using
number parameter)Disconnected (state: close)
After initiating connection, returns QR code:Raw QR code string
QR code as base64-encoded image
Pairing code (if number parameter provided)
Examples
Response Examples
Already Connected
QR Code Response
Pairing Code Response
Error - Instance Not Found
Connection Flow
- Call the connect endpoint - Initiates connection and receives QR code
- Display QR code to user - Show the
base64image for scanning - User scans QR code - Open WhatsApp > Settings > Linked Devices > Link a Device
- Monitor connection status - Poll the
/instance/connectionState/:instanceNameendpoint - Connection confirmed - Status changes to
open
QR Code Expiration: QR codes expire after approximately 60 seconds. If the user doesn’t scan in time, call the endpoint again to get a fresh QR code.
Connection States
| State | Description | Action Required |
|---|---|---|
| open | Instance is connected | None - ready to use |
| connecting | Connection in progress | Display QR code |
| close | Instance is disconnected | Call connect endpoint |
Integration Types
This endpoint behaves differently based on your integration:WHATSAPP-BAILEYS
- Generates QR code for WhatsApp Web authentication
- Supports pairing code with phone number
- Requires QR code scan or pairing code entry
WHATSAPP-BUSINESS
- Does not require QR code
- Connection managed through Meta Business API
- Returns connection state only
Error Handling
The API returns standard HTTP status codes:200- Success (returns QR code or connection state)400- Bad request (instance doesn’t exist)401- Unauthorized (invalid API key)500- Internal server error
- Instance doesn’t exist: Verify the
instanceNameis correct - Already connecting: Wait for current connection attempt to complete or timeout
- Authentication failed: Check that your API key is valid
Best Practices
- Implement timeout logic: If QR code isn’t scanned within 60 seconds, request a new one
- Poll connection state: Check connection status every 3-5 seconds during QR code display
- Handle reconnection: If instance disconnects, automatically call connect endpoint
- Store connection state: Cache the connection state to minimize API calls
- User experience: Show a clear countdown timer for QR code expiration
Webhook Integration
Instead of polling, you can configure webhooks to receive connection updates:CONNECTION_UPDATE Event
CONNECTION_UPDATE event when creating your instance to receive real-time connection notifications.