Skip to main content

Connection

Generating the qrCode

The starting point for communication with the API is generating the qrCode. Once the qrCode is generated, you can scan it using your mobile device to enable message exchange between the API and your system.

Commandgenerate_qrcode.aspx
MethodPOST
Body
{ 
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)..."
}

user_agent Provide the full UserAgent string according to your browser.

Response

SUCCESS → returns qrCode image in SVG base64 format:

{
"qr": "data:image/svg+xml;base64,PD94b...",
"status":1,
"error":"",
"ttl":20
}

ERROR → returns the described error:

{
"status": 0,
"error": "Connection already established",
"ttl": 0
}

Once the device scans the qrCode, a series of events will be returned via the PostBack URL:

Connection Status

Commandstatus.aspx
MethodGET
Response

Connection information:

{
"status": 10, // status code
"statusString": "WhatsAppAuthenticated", // connection status as text
"connected": true, // whether connected (true) or not (false)
"ConnectionInfo": {
"lg": "en",
"lc": "US",
"phone": {
"device_model": "iPhone 4S",
"wa_version": "2.21.10.25",
"mcc": "724",
"os_version": "9.3.5",
"os_build_number": "undefined",
"device_manufacturer": "Apple",
"mnc": "031"
},
"battery": 83,
"tos": 0,
"pushname": "Atendimento Maria",
"protoVersion": [
0,
17
],
"plugged": false,
"platform": "iphone",
"wid": "5511987654321@s.whatsapp.net",
"connected": true,
"isResponse": "false",
"binVersion": 10,
"locales": "en-US,pt-BR"
},
"WebID": "6D6307C3-2973-4468-85FA-D047CB8E1F2E",
"Webhook": "http://my-erp.com.br&wid=6D6307C3-2973-4468-85FA-D047CB8E1F2E",
"UserAgent": "Chrome",
"CanRestoreConnection": true, // true if connection can be restored (without qrCode)
"stats": {
"Contacts": 72,
"Chats": 32,
"SentBytes": 0,
"ReceveidBytes": 0
},
"storage": {
"Name": "6D6307C3-2973-4468-85FA-D047CB8E1F2E",
"Bytes": 15544238,
"Files": 107,
"Subs": [
{
"Name": "media",
"Bytes": 11817360,
"Files": 27,
"Subs": null
},
{
"Name": "profile",
"Bytes": 1843594,
"Files": 52,
"Subs": null
},
{
"Name": "thumb",
"Bytes": 224238,
"Files": 27,
"Subs": null
}
]
}
}

Status codes and their string equivalents:

IntString
0noConnection
1webSocketOpenining
2webSocketOpen
3waitForQRAuthentication
4Starting
10WhatsAppAuthenticated
11WhatsAppAuthenticatedConnectionClosed
13WhatsAppNotAuthenticated

Disconnect

Completely disconnects from WhatsApp (qrCode must be generated again).

Commanddisconnect.aspx
MethodGET
Response

SUCCESS → connection information:

    {
"status": 0,
"statusString": "noConnection",
"connected": false,
...
}

End Session

Partially disconnects from WhatsApp (possible to reconnect using the restore_session.aspx command).

Commandclose_session.aspx
MethodGET
Response

SUCCESS → connection information:

{
"sucesso": true,
"Status": "{\"status\":0,\"statusString\":\"noConnection\"..."
}

Save Session

Saves the current connection state and allows reconnection. This is executed automatically after reading the qrCode.

Commandsave_session.aspx
MethodGET
Response

SUCCESS:

{
"sucesso": true
}

Restore Session

Restores a previously ended session (using the close_session.aspx command).

Commandrestore_session.aspx
MethodGET
Response

SUCCESS → connection information:

{
"sucesso": true,
"Status": "{\"status\":10,\"statusString\":\"WhatsAppAuthenticated\"..."
}

Clear Instance

Completely clears saved instance data. Resets stored files and cache. (Does not affect WhatsApp data)

Commandclear.aspx
MethodGET
Response
{
"status": true,
"message": "clear ok"
}

Update Settings

Updates connection settings.

Important!

If you change the WebHook using the set_config.aspx command, using the system via browser will stop working.

If you want to use both methods (browser and API), consider changing the WebHook via the system administration interface (Access the admin area > Edit Instance > API > PostBack URL).

Commandset_config.aspx
MethodPOST
Body
{ 
"webhook": "https://my-system.com/newWebHook", // event return URL
"user_agent" : "Opera", // sets which browser is used
"APIVersionCanBulk": false, // enables BULK return
"APIVersion": "1.0" // sets API version
}
Response

SUCCESS → Returns connection data:

{
"status": 10,
"statusString": "WhatsAppAuthenticated",
"connected": true,
"Webhook": "https://my-system.com/newWebHook",
"UserAgent": "Opera",
...
}