Connecting to Green API by phone number#
November 30, 2023
With the new release 5.44.24.11, the getAutorizationCode method has been added to the API to connect a WhatsApp account to an instance by phone number. This is an easier way to connect the API functionality and the client account. Previously, connection was only available via QR code.
QR code and shortcomings#
The method of connecting via QR code had a number of disadvantages:
-
The generated QR code was constantly updated;
-
The QR code could not be forwarded to the client;
-
The phone may not have a camera to scan the QR code;
-
QR code scanning causes difficulties if the customer is on the same phone;
-
Connecting by QR code may cause an error.
Linking by number and convenience#
The new method of connecting by phone number getAutorizationCode gets rid of the disadvantages of QR code.
- Now you can send the connection code of your WhatsApp account and instance via mail or messeng assets.
- No need to scan or use third-party equipment.
- You can copy and paste the code in the
Link by phone number
field. Or enter the code manually yourself. - Now you can link your account without letting your phone out of your hands.
You can link by phone number in two ways - through your account and via API.
Get a code through your account#
To call the code to link a phone number to an instance in the personal cabinet, you need to:
- Log in to the personal cabinet;
-
Create/select the instance you want to link;
For testing, we recommend using instances at the
Developer
tariff -
Click on the
Link with phone number
button;
-
Enter the phone number in international format;
Do not use pluses, zeros, parentheses, or hyphens when entering a phone number in international format. For example: 0100123456789@c.us.
-
Press
Next
then you will see the code that you need to enter on your phone;
Code in personal cabinet. -
On your phone, open the WhatsApp or WhatsApp Business application, go to
Linked devices
->Link a device
->Link with phone number instead
and enter the code from personal account.
1. Linking the device. 2. Link by phone number button. 3. Field for entering the code.
Get the code through the method getAutorizationCode#
To get the code via API, you need to call the method in your development environment or test the method in Postman.
POST https://api.green-api.com/waInstance{{idInstance}}/getAuthorizationCode/{{apiTokenInstance}}
For idInstance
and apiTokenInstance
request parameters, refer to Before You start. In the body of the method request, specify the phone number you want to link to the instance:
{
"phoneNumber": 441234567890
}
The authorization code will come in the body of the response:
{
"status": true,
"code":"GAPI2018"
}
You can read more about how the method works in the documentation.
Result#
Done. Now it's possible to get the phone number authorization code in WhatsApp and link your account even more conveniently.