4ce4204b6c
CI / Lint (push) Failing after 2s
CI / Build (push) Has been skipped
SDK CI / PHP SDK (push) Failing after 1s
Split PHP SDK / PHP SDK tests (push) Failing after 1s
CI / Test (push) Failing after 1s
CI / Dashboard (push) Failing after 0s
SDK CI / JavaScript SDK (push) Failing after 0s
SDK CI / Python SDK (push) Failing after 2s
SDK CI / Java SDK (push) Failing after 1s
Split PHP SDK / Mirror sdk/php -> rmyndharis/openwa-php (push) Has been skipped
CI / Test (PostgreSQL migrations) (push) Failing after 7m47s
CI / Docker Build (push) Has been skipped
2.4 KiB
2.4 KiB
Session Phone-Number Pairing
OpenWA supports linking an existing WhatsApp account to a session by phone number as an alternative to scanning a QR code.
This flow returns an 8-character pairing code that the user enters in WhatsApp on their phone.
This does not create or register a new WhatsApp account. It only links an existing WhatsApp account as a companion device for an OpenWA session.
Flow
[Create Session]
│
▼
[Start Session]
│
▼
[Request Pairing Code]
│
▼
[Enter Code in WhatsApp]
│
▼
[Session Connected]
1. Create a Session
curl -X POST http://localhost:2785/api/sessions \
-H "X-API-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "support-bot"
}'
Save the returned session id.
2. Start the Session
curl -X POST http://localhost:2785/api/sessions/{sessionId}/start \
-H "X-API-Key: $API_KEY"
The session must be started before requesting a pairing code.
3. Request a Pairing Code
curl -X POST http://localhost:2785/api/sessions/{sessionId}/pairing-code \
-H "X-API-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"phoneNumber": "628123456789"
}'
phoneNumber must be digits only in international format: country code + number, without +, spaces, or dashes.
Example values:
| Country | Example |
|---|---|
| Indonesia | 628123456789 |
| Spain | 34612345678 |
| United States | 14155552671 |
Response
{
"pairingCode": "ABCD1234",
"status": "qr_ready"
}
4. Enter the Code in WhatsApp
On the phone that owns the WhatsApp account:
- Open WhatsApp.
- Go to Settings.
- Open Linked Devices.
- Choose Link with phone number.
- Enter the pairing code returned by OpenWA.
After the code is accepted, the OpenWA session should move to a connected/ready state.
Troubleshooting
- If OpenWA returns
Session is not started, callPOST /api/sessions/{sessionId}/startfirst. - If OpenWA returns
Session is already authenticated, the account is already linked and no pairing code is needed. - If the phone number is rejected, send digits only in international format, without
+, spaces, or punctuation. - If you want to create a brand-new WhatsApp account programmatically, that is outside OpenWA's scope. OpenWA only links an existing WhatsApp account.