Connecting a phone number to the GREEN-API service#
You can connect your WhatsApp phone number to the API instance in your integration in two ways.
Important!
Before retrieving the authorization code, make sure the instance is unauthorized. To deauthorize, use the method Logout method to deauthorize.
Connect via QR code#
-
Get a QR code via websocket.
- Create a file in HTML format;
- Add the code from the example;
The connection is set up by JavaScript code.
- Create local page hosting;
- Put
apiUrl,idInstanceandapiTokenInstancein the fields.You can find out where to find
apiUrl, idInstance and apiTokenInstance in article; - Click on the
Get QRbutton. The QR code will appear on the screen.
When receiving a QR code via websocket, the
Get QRbutton can be clicked several times and you will always be returned an up-to-date image of the QR code. -
- You can get the QR code directly through your browser's search bar.
https://qr.green-api.com/waInstance1101******/0654934b277d4ef693b01ab073d9cd2e97f02db9a53****** -
Through QR method.
Code example.- Add
apiUrl,idInstanceandapiTokenInstancefrom console; - The
messagefield will return abase64encoded QR code string; - To see an image with a QR code, put
data:image/png;base64, {message}in the browser search bar.
- Add
Attention!
For successful authorization via QR code, you need to scan it within 20 seconds. Otherwise, the QR code will be updated on the WhatsApp side and the whole procedure will have to be started again.
Bind by phone number#
{{apiUrl}}/waInstance{{idInstance}}/getAuthorizationCode/{{apiTokenInstance}}
- Send a POST request using the
getAutoriationCodemethod. - Customize the body of the request - enter the phone number in international format in the
phoneNumberfield.Do not use plus signs, zeros, parentheses, or dashes when entering the phone number in international format. For example: 0100123456789@c.us.
- The
codefield in the body of the reply will show the eight-digit code to be entered in the WhatsApp app.
Notation
The phone number method has no time limit for authorization. You can easily send the code to another person by mail or messenger. No camera is required for authorization by phone number. You can read more in our article.