Connect your number to WhatsApp with a pairing code
By the end, the phone number will be connected to your instance, with no QR code to scan. This helps when you cannot point a camera at the screen, for example when you set everything up from the phone itself.
Prerequisites
Section titled “Prerequisites”- An instance created in the dashboard, with its ID and token (Getting started).
- The phone with WhatsApp installed and the number to be connected.
curlin the terminal.
In the examples, replace INSTANCIA_ID with the instance ID and TOKEN with its token.
1. Start the connection
Section titled “1. Start the connection”The pairing code only exists after the connection starts:
curl -X POST https://api.zap.nigora.com.br/v1/instances/INSTANCIA_ID/connect \ -H "Authorization: Bearer TOKEN"The response is 202 with the connectionStatus. It only confirms that the connection started. If the instance is suspended or has a pending payment, the response is 402 with instance_suspended.
2. Request the code
Section titled “2. Request the code”Send the phone of the number to be connected, with country and area codes:
curl -X POST https://api.zap.nigora.com.br/v1/instances/INSTANCIA_ID/pairing-code \ -H "Authorization: Bearer TOKEN" \ -H "Content-Type: application/json" \ -d '{ "phone": "5511999999999" }'Expected result:
{ "code": "ABCD-1234" }Your code will be different, with 8 characters. If the API takes a few seconds, that is normal: it waits for the connection to be ready before generating the code.
3. Enter the code on the phone
Section titled “3. Enter the code on the phone”On the phone:
- Open WhatsApp.
- Go to Linked devices.
- Tap Link with phone number.
- Enter the code from the previous step.
If WhatsApp rejects the code, repeat step 2 to request another one.
4. Confirm the connection
Section titled “4. Confirm the connection”curl https://api.zap.nigora.com.br/v1/instances/INSTANCIA_ID \ -H "Authorization: Bearer TOKEN"Expected result, with connectionStatus set to connected and the number in phone:
{ "connectionStatus": "connected", "phone": "5511999999999" }The real response has other instance fields. While the state is not connected, check again in a few seconds. To be notified without polling, set up the instance.connected webhook.
If something goes wrong
Section titled “If something goes wrong”| Status | Code | What to do |
|---|---|---|
400 |
invalid_phone |
The phone must have 12 or 13 digits, or 10 to 11 without the 55 |
409 |
instance_not_connected |
No connection is in progress: repeat step 1 and request the code right after |
401 |
invalid_token |
Check the token and the instance ID |
Next steps
Section titled “Next steps”- Connection: QR code, instance states, disconnecting and restarting.
- Send a message with Node.js: send the first message from the connected number.
- Receive messages by webhook: receive the replies in your system.