Get QR code via websocket#
Along with getting a QR code using QR method, it is possible to get a QR code via websocket connection. Timeout for scanning a QR code is 100 seconds. During this time, the QR code must be scanned. To get a QR code, the instance must be in an unauthorized state. If the instance is authorized, you have first to log out the instance using Logout method.
After successful scanning the QR code and authorizing the instance, an incoming notification in the form of Instance Status is generated.
To get a QR code you have to establish a websocket-connection at:
{{apiUrl}}/waInstance{{idInstance}}/scanqrcode/{{apiTokenInstance}}
For apiUrl, idInstance and apiTokenInstance request parameters, refer to Before you start section.
Important
This method receives a QR code identical to that obtained using the QR method.
This method allows only a single session, whereas the QR method can be called from multiple devices.
Errors for this method and the QR method are identical.
Example of getting a QR code in a browser#
You can see an example of getting a QR code through websocket in the file websocketExampleQRcode
Response#
Response parameters#
| Parameter | Type | Description |
|---|---|---|
type | string | Message type, Possible values qrCode, timeout, error, passkeyRequired, alreadyLogged |
message | string | Message content. Takes on different values depending on parameter type |
Got QR code#
| Parameter | Type | Descroption |
|---|---|---|
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 |
connect closed - no connection to the server | ||
not ready - the instance is not ready to send a QR code | ||
Instance starting - the instance is starting | ||
socket not open - open a socket to receive a QR code | ||
is in the logout process - the instance is clearing its cache; please wait until the cache clearing is complete |
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 already logged |
QR code scan timeout expired#
| Parameter | Type | Description |
|---|---|---|
type | string | timeout - the timeout within which a QR code must be scanned has expired. Timeout for scanning a QR code is 100 seconds |
message | string | Takes on the value instance:${idInstance} timeout reading qr code |