QR#
It is recommended to use the Phone Number Authorization Method
The method is aimed for getting QR code. To authorize your instance, you have to scan a QR code from application WhatsApp Business on your phone. You can also get a QR code and authorize your instance in console. The procedure for authorizing an instance in console is described in section Before you start.
QR code is updated every 20 seconds, therefore, it is recommended to request the method for getting a QR code with a delay in 1 second.
To get a QR code, the instance must have an unauthorized status. If the instance is authorized, you have first to log out the instance using Logout method. After successful scanning a QR code and authorizing the instance incoming notification in form of Instance Status is generated.
You can also get a QR code via websocket-connection
Request#
To get a QR code, you have to execute a request at:
{{apiUrl}}/waInstance{{idInstance}}/qr/{{apiTokenInstance}}
For apiUrl
, idInstance
and apiTokenInstance
request parameters, refer to Before you start section.
Response#
Response parameters#
Parameter | Type | Description |
---|---|---|
type | string | Message type, possible variants qrCode , error , alreadyLogged |
message | string | Message content. Takes on different values depending on type |
Got QR code#
Parameter | Type | Description |
---|---|---|
type | string | qrCode - got QR code image |
message | string | base64 QR code image. To display in the browser, you need to add a string data:image/png;base64, {message} |
Error occurred#
Parameter | Type | Description |
---|---|---|
type | string | error - an error is occurred |
message | string | Error description |
Instance has auth. You need to make log out - there is authorization data, but they are not suitable for authorization, it is necessary to execute the logout method and rescan the QR code |
Getting a QR code can take up to 10 minutes
Instance already authorized#
Parameter | Type | Description |
---|---|---|
type | string | alreadyLogged - instance is already authorized. To get a QR code, you have first to log out of your instance using Logout method |
message | string | Takes on the value instance account already authorized |
Example of getting a QR code in a browser#
https://qr.green-api.com/waInstance{{idInstance}}/{{apiTokenInstance}}
For idInstance
and apiTokenInstance
request parameters, refer to Before you start section.
You need to replace the idInstance and apiTokenInstance values with yours to get a link like this:
https://qr.green-api.com/waInstance11015502/ccc44689b17435537c15a939d0a478b71c3bd7d7d52d312345
You can also see an example of getting a QR code in a browser in the file browserExampleQRcode
QR errors#
For a list of errors common to all methods, refer to Common errors section
HTTP code | Error identifier | Description |
---|---|---|
200 | OK | Instance already logged |
When getting the QR code from the links above, an error may appear and it will take an infinitely long time to download the code 1. Check the correctness of the generated link. 2. Check the correctness of idInstance and apiTokenInstance data |
Request examples#
import requests
url = "{{apiUrl}}/waInstance{{idInstance}}/qr/{{apiTokenInstance}}"
payload = {}
headers= {}
response = requests.request("GET", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
curl --location '{{apiUrl}}/waInstance{{idInstance}}/qr/{{apiTokenInstance}}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
.append({{apiUrl}})
.append("/waInstance").append({{idInstance}})
.append("/qr/")
.append({{apiTokenInstance}});
var response = restTemplate.exchange(requestUrl.toString(), HttpMethod.GET, null, String.class);
System.out.println(response);
var requestUrl = new StringBuilder();
requestUrl
.append({{apiUrl}})
.append("/waInstance").append({{idInstance}})
.append("/qr/")
.append({{apiTokenInstance}});
var response = Unirest.get(requestUrl.toString())
.header("Content-Type", "application/json")
.asString();
System.out.println(response);
Sub qr()
Dim url As String
Dim http As Object
Dim response As String
' The apiUrl, idInstance and apiTokenInstance values are available in console, double brackets must be removed
url = "{{apiUrl}}/waInstance{{idInstance}}/qr/{{apiTokenInstance}}"
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", url, False
http.Send
response = http.responseText
Debug.Print response
' Outputting the answer to the desired cell
' Range("A1").Value = response
Set http = Nothing
End Sub