Table of Contents

Creating a session via API

This command opens a WhatsApp session to link it to the service. After opening, you must authorize WhatsApp through the mobile app and QR code. If the session is no longer needed, close it using session-delete.

Request command

To create a session, send a POST request to:

https://whatsgate.org/api/v1/session-create

Request body object for QR authorization

The request body must contain:

{
  "name" : "My WhatsApp",
  "callback" : "https://callback.my/script.handler"
}

Request body object for CODE authorization

The request body must contain:

{
  "name" : "My WhatsApp",
  "callback" : "https://callback.my/script.handler",
  "auth_type" : "CODE",
  "number" : "79999999999"
}

Response object

Successful response object

{
  "result": "OK",
  "data" : {
     "id": 151,
     "name": "My WhatsApp",
     "unique_id": "6345454545454",
     "status": "PENDING",
     "callback": "https://callback.my/script.handler",
     "date_add": "2022-10-11 19:30:14",
     "qr": null,
     "status_name": "Initialization",
     "pushname": null,
     "wid": null,
     "qr_link": "https://whatsgate.org/qr/6345454545454"
  }
}

QR authorization window

The QR authorization window is available at:

https://whatsgate.org/qr/<unique_id>

For convenience, this link is returned in qr_link when creating a session. The QR code in this window is updated periodically and changes to a success or error image after authorization.

Embedding the QR page

This page can be embedded into your app via iframe, and parent page can receive messages from it. Embedding example:

<h1>QR test code</h1>

<iframe src="https://whatsgate.org/qr/6345454545454" width="310" height="310" style="border: none;">

</iframe>

<div class="log" id="log">

</div>

<script>
    window.addEventListener("message", function(event) {

        console.log(event);

        if (event.origin !== 'https://whatsgate.org') {
            // something came from an unknown domain; ignore it
            return;
        }

        if(typeof event.data !== 'object') {
            // message must be an object
            return;
        }

        if(!('module' in event.data) && event.data.module !== 'qr'){
            // object must contain module field with value qr
            return;
        }

        //if we're here, the message is valid; output it
        console.log( "received: " + event.data.message);
        //append message to parent-page log
        document.getElementById('log').append("received: " + event.data.message, document.createElement("br"));
    });
</script>

The message object is in event.data and has this format:

{
  "module" : "qr",
  "message" : "<message>"
}