Skip to content

Endpoint

iBNu Maksum edited this page Oct 25, 2023 · 6 revisions

Info

All End point started with your http_base_url

/auth

to create Basic Auth, use phone number with country code

Indonesia is +62, phone number 0812345, result is 62812345

combine with AUTH_BASIC_PASSWORD will be 62812345:83e4060e-78e1-4fe5-9977-aeeccd46a2b8

encode it to base64 result: NjI4MTIzNDU6ODNlNDA2MGUtNzhlMS00ZmU1LTk5NzctYWVlY2NkNDZhMmI4

Screen Shot 2022-06-06 at 14 27 58

This is important as it will resume session after you restart services, based on that username, as is tied to phone number Screen Shot 2022-06-06 at 12 31 04

Make request

GET http://127.0.0.1:3000/api/v1/whatsapp/auth
HEADER: 'Authorization: Basic NjI4MTIzNDU6ODNlNDA2MGUtNzhlMS00ZmU1LTk5NzctYWVlY2NkNDZhMmI4'

PHP Sample

<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_PORT => "3000",
  CURLOPT_URL => "http://127.0.0.1:3000/api/v1/whatsapp/auth",
  CURLOPT_HTTPHEADER => [
    "Authorization: Basic NjI4MTIzNDU6ODNlNDA2MGUtNzhlMS00ZmU1LTk5NzctYWVlY2NkNDZhMmI4"
  ],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);

Terminal Sample

curl --request GET \
  --url http://127.0.0.1:3000/api/v1/whatsapp/auth \
  --header 'Authorization: Basic NjI4MTIzNDU6ODNlNDA2MGUtNzhlMS00ZmU1LTk5NzctYWVlY2NkNDZhMmI4'

RESULT

{
	"status": true,
	"code": 200,
	"message": "Successfully Authenticated",
	"data": {
		"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXQiOnsiamlkIjoiNjI4MTIzNDUifSwiaWF0IjoxNjU0NDkzNDEzfQ.kOlR0g_aEpKbpD19g9y4UBLA37_bl9A7pu8cbogZ5_4"
	}
}

this token only for 62812345, now prepare your phone with active whatsapp, open linked devices menu, and do next step

/login

Login is tricky, because the result is HTML, i use insomnia.rest to run this script

Make request

POST http://127.0.0.1:3000/api/v1/whatsapp/login
HEADER: 'Content-Type: application/x-www-form-urlencoded; Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXQiOnsiamlkIjoiNjI4MTIzNDUifSwiaWF0IjoxNjU0NDkzNDEzfQ.kOlR0g_aEpKbpD19g9y4UBLA37_bl9A7pu8cbogZ5_4'

PHP Sample

<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_PORT => "3000",
  CURLOPT_URL => "http://127.0.0.1:3000/api/v1/whatsapp/login",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "=",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXQiOnsiamlkIjoiNjI4MTIzNDUifSwiaWF0IjoxNjU0NDkzNDEzfQ.kOlR0g_aEpKbpD19g9y4UBLA37_bl9A7pu8cbogZ5_4",
    "Content-Type: application/x-www-form-urlencoded"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Terminal Sample

curl --request POST \
  --url http://127.0.0.1:3000/api/v1/whatsapp/login \
  --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXQiOnsiamlkIjoiNjI4MTIzNDUifSwiaWF0IjoxNjU0NDkzNDEzfQ.kOlR0g_aEpKbpD19g9y4UBLA37_bl9A7pu8cbogZ5_4' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data =

RESULT

    <html>
      <head>
        <title>WhatsApp Multi-Device Login</title>
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
      </head>
      <body>
        <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAABlBMVEX" />
        <p>
          <b>QR Code Scan</b>
          <br/>
          Timeout in 60 Second(s)
        </p>
      </body>
    </html>

Scan The result QRcode with whatsapp in your phone

/login/pair

WhatsApp now have new feature, Login using pair code

Todo this, you need to change .env.
and change value WHATSAPP_USER_AGENT_NAME to WHATSAPP_USER_AGENT_NAME="Chrome (Mac OS)"

Latest version has fix this, and no need to change WHATSAPP_USER_AGENT_NAME


Make request

POST http://127.0.0.1:3000/api/v1/whatsapp/login/pair
HEADER: 'Content-Type: application/x-www-form-urlencoded; Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXQiOnsiamlkIjoiNjI4MTIzNDUifSwiaWF0IjoxNjU0NDkzNDEzfQ.kOlR0g_aEpKbpD19g9y4UBLA37_bl9A7pu8cbogZ5_4'

PHP Sample

<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_PORT => "3000",
  CURLOPT_URL => "http://127.0.0.1:3000/api/v1/whatsapp/login/pair",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "=",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXQiOnsiamlkIjoiNjI4MTIzNDUifSwiaWF0IjoxNjU0NDkzNDEzfQ.kOlR0g_aEpKbpD19g9y4UBLA37_bl9A7pu8cbogZ5_4",
    "Content-Type: application/x-www-form-urlencoded"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Terminal Sample

curl --request POST \
  --url http://127.0.0.1:3000/api/v1/whatsapp/login/pair \
  --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXQiOnsiamlkIjoiNjI4MTIzNDUifSwiaWF0IjoxNjU0NDkzNDEzfQ.kOlR0g_aEpKbpD19g9y4UBLA37_bl9A7pu8cbogZ5_4' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data =

RESULT

    {
	"status": true,
	"code": 200,
	"message": "Successfully Generated Pairing Code",
	"data": {
		"paircode": "ARHK-SYNP",
		"timeout": 160
	}
    }

write the code in your WhatsApp

/registered

Check if whatsapp account exists?

curl -X 'GET' \
  "http://127.0.0.1:3000/api/v1/whatsapp/registered?msisdn=$PHONE_NUMBER" \
  -H "Authorization: Bearer $TOKEN" \
  -H 'accept: application/json'

/send/text

Terminal Sample

curl -X 'POST' \
  'http://127.0.0.1:3000/api/v1/whatsapp/send/text' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: multipart/form-data' \
  -F "msisdn=$PHONE_NUMBER" \
  -F 'message=Hello World'

/send/location

/send/contact

/send/link

/send/document

Terminal Sample

curl -X 'POST' \
  'http://127.0.0.1:3000/api/v1/whatsapp/send/document' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: multipart/form-data' \
  -F "msisdn=$PHONE_NUMBER" \
  -F 'document=@document.pdf;type=application/pdf'

/send/image

Terminal Sample

curl -X 'POST' \
  'http://127.0.0.1:3000/api/v1/whatsapp/send/image' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: multipart/form-data' \
  -F "msisdn=$PHONE_NUMBER" \
  -F 'caption=<Image Caption Here>' \
  -F 'image=@image.jpg;type=image/jpeg' \
  -F 'viewonce=false'

/send/audio

/send/video

Terminal Sample

curl -X 'POST' \
  'http://127.0.0.1:3000/api/v1/whatsapp/send/video' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: multipart/form-data' \
  -F "msisdn=$PHONE_NUMBER" \
  -F 'caption=<Video Caption Here>' \
  -F 'video=@video.mp4;type=video/mp4' \
  -F 'viewonce=false'

/send/sticker

/logout

Terminal Sample

curl -X 'GET' \
  "http://127.0.0.1:3000/api/v1/whatsapp/logout \
  -H "Authorization: Bearer $TOKEN" \
  -H 'accept: application/json'

IF YOU SEE THIS MESSAGE, THEN THIS DOCUMENTATION IS STILL ONGOING, NOT FINISHED YET