QR#
The method is intended for getting a QR code.
To authorize an instance, you need to scan the QR code from the Telegram messenger on your phone.
Entering a password
If a password is set, the instance will move to the pendingPassword state until authorization or logout. To complete authorization, send the password using the SendAuthorizationPassword method
A QR code has a limited lifetime, so it is recommended to request a new QR code every 5 seconds.
After the QR code is scanned successfully and the instance is authorized, an incoming notification of the Instance state kind is generated.
The method uses limits on the request rate per second.
Request#
To get a QR code, you need to execute a request at:
{{apiUrl}}/waInstance{{idInstance}}/qr/{{apiTokenInstance}}
To get the apiUrl, idInstance and apiTokenInstance request parameters, refer to the Before you start section.
Response#
Response fields#
| Field | Type | Description |
|---|---|---|
type | string | Message type, possible values qrCode, error, alreadyLogged, already_registered |
message | string | Message content. Takes different values depending on the value of the type field |
A QR code image has been received#
| Field | Type | Description |
|---|---|---|
type | string | qrCode - a QR code image has been received |
message | string | QR code image in base64 encoding. To display it in a browser, you need to add the string data:image/png;base64, {message} |
An error occurred#
| Field | Type | Description |
|---|---|---|
type | string | error - an error occurred |
message | string | Error description |
timeout - Telegram servers are unavailable | ||
not_ready - The instance is not ready for work. Try again. If the error persists - contact technical support | ||
connection_closed - The request was rejected by Telegram servers. Try again. If the error persists - contact technical support |
The instance is already authorized#
| Field | Type | Description |
|---|---|---|
type | string | already_registered - the instance is already authorized. To get a QR code, you first need to log out the instance using the Logout method |
message | string | Takes the value instance account already authorized |
Example of getting a QR code in a browser#
https://qr.green-api.com/waInstance{{idInstance}}/{{apiTokenInstance}}/telegram
To get the idInstance and apiTokenInstance request parameters, refer to the Before you start section.
You need to replace the idInstance and apiTokenInstance values with your own to get a link of the form:
https://qr.green-api.com/waInstance4100000000/abcdef12345fghij67890klmno/telegram
Errors#
For the list of errors common to all methods, see the Common errors section.
| HTTP code | Error identifier | Description |
|---|---|---|
| 200 | OK | The instance is already authorized |
| When getting a QR code by the links above, an error may occur and the code may load indefinitely | 1. Check that the generated link is correct. 2. Check that the idInstance and apiTokenInstance data are correct |
Code 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