Link with a code
Link a WhatsApp account by typing a code on the phone instead of scanning a QR code.
A link code is an alternative to the QR code when you can't point the phone's camera at the screen, for example on a remote server. You give open-wa the account's phone number, open-wa prints a short code, and you type it into WhatsApp on that phone.
Set the phone number
Set linkCode to the account's full international number, digits only: no
+, spaces, brackets or dashes. Use 447123456789, not +44 7123 456789. A
chat ID such as 447123456789@c.us is for sending messages, not for
linkCode.
SDK: pass it to create(), which prints the code and resolves once the
session is ready.
import { create } from '@open-wa/wa-automate';
const client = await create({
sessionId: 'link-code-demo',
linkCode: '447123456789',
});
console.log('WhatsApp session ready');npm install @open-wa/wa-automate
node index.mjsEasy API: there's no command-line flag. Set linkCode in your
wa.config.js, or set the WA_LINK_CODE environment variable:
WA_LINK_CODE=447123456789 npx @open-wa/wa-automate --session-id salesThe terminal prints the code on a line that starts with
Link code (local console only):.
Enter the code on your phone
On the phone that owns the number:
- Open WhatsApp.
- Open Settings on iPhone, or the ⋮ menu on Android, then Linked devices.
- Tap Link a device.
- Choose Link with phone number instead.
- Type the code from the terminal and confirm.
Check the session is ready
create() only returns once the session can send. For the Easy API, wait until
/health reports connected: true and session.ready: true. Printing a code
doesn't mean the phone finished linking.
Codes expire. If the phone rejects the code or login times out, stop open-wa and start it again to get a fresh code. Once linked, later starts reuse the saved login and don't print a code; see Log in and keep a session.
Was this helpful?
Your answer includes the page path and docs version.
