Skip to main content
Pairing code authentication lets you link Baileys to WhatsApp using an 8-digit code instead of a QR code. This is useful in headless environments where displaying a QR code is inconvenient, or when you want to link a device by entering a code on your phone manually.
Pairing code is a method to connect WhatsApp Web without scanning a QR code. It is not the Mobile API. You can only link one device per phone number using this method. See the WhatsApp FAQ for details.

Setup

1

Create the socket

Create the socket without rendering a QR code. You can simply ignore the qr field on connection.update while using pairing codes.
The legacy printQRInTerminal option is deprecated and should not be set. Don’t render the QR string while pairing by code — just call requestPairingCode instead.
2

Request a pairing code

Check sock.authState.creds.registered before requesting a code. If the socket is already registered (i.e., credentials are already present from a previous session), you do not need to request a new code.
The returned code is an 8-digit string you enter on your phone.
3

Enter the code on your phone

On your phone, open WhatsApp and go to Settings → Linked Devices → Link a Device. Select Link with phone number instead and enter the 8-digit code displayed in your terminal.Once you confirm on the phone, the connection.update event fires with connection: 'open'.

Phone number format

The phone number you pass to requestPairingCode must follow these rules:
  • Include the country code (e.g., 1 for the US, 44 for the UK)
  • Use digits only — no +, (, ), or - characters
  • Do not include spaces

Complete example

The following example uses readline to prompt for the phone number at runtime, matching the pattern used in the official example script.
The qr field in connection.update fires even in pairing code mode. Use it as your trigger to call requestPairingCode rather than calling it immediately after creating the socket, because the socket may not be ready yet.
Combine this with useMultiFileAuthState so the pairing code is only needed once. On subsequent runs, the saved credentials reconnect automatically without a new code. See Save and restore WhatsApp sessions.