API Documentation

Cara penggunaan & contoh inputan

1. Memulai

Semua endpoint memakai base URL server Anda, format JSON, dan method HTTP.

BASE URL: https://chat.binariscorp.co.id
LOKAL: http://localhost:3000
Alur singkat:
  1. POST /api/accounts — buat akun
  2. POST /api/accounts/:id/pair — ambil kode pairing (atau scan QR)
  3. Masukkan kode di WhatsApp → status jadi online
  4. POST /api/accounts/:id/send — kirim pesan

2. Format Response

Semua endpoint selalu membalas JSON dengan pola:

Sukses

{
  "ok": true,
  "data": { ... }
}

Gagal

{
  "ok": false,
  "error": "pesan error"
}

HTTP status: 200 sukses · 400 input salah · 404 tidak ditemukan · 409 konflik (mis. belum online) · 502 gagal dari server WhatsApp.

3. Endpoint Akun

GET /api/accounts

Daftar semua nomor beserta status & statistiknya.

▸ Contoh
curl https://chat.binariscorp.co.id/api/accounts
▸ Response
{
  "ok": true,
  "data": [{
    "id": "wa_mw0g9t9arf40m",
    "label": "Sales",
    "status": "online",
    "phone": "6281234567890",
    "name": "Budi",
    "stats": { "sent": 12, "received": 5 },
    "pairing": null,
    "lastError": null
  }]
}
POST /api/accounts

Tambah nomor baru. Koneksi langsung dimulai (status QR/pairing siap).

FieldTipeWajibKeterangan
labelstringtidakNama akun, contoh: "Sales"
▸ Contoh input
curl -X POST https://chat.binariscorp.co.id/api/accounts \
  -H "Content-Type: application/json" \
  -d '{"label":"Sales"}'
▸ Response
{
  "ok": true,
  "data": {
    "id": "wa_mw0g9t9arf40m",
    "label": "Sales",
    "status": "qr",
    "stats": { "sent": 0, "received": 0 }
  }
}
GET /api/accounts/:id

Detail satu akun. :id = id dari daftar akun.

▸ Contoh
curl https://chat.binariscorp.co.id/api/accounts/wa_mw0g9t9arf40m
GET /api/accounts/:id/qr

QR code login (data URL PNG) — hanya saat status qr/connecting.

▸ Contoh
curl https://chat.binariscorp.co.id/api/accounts/wa_mw0g9t9arf40m/qr
POST /api/accounts/:id/pair

Minta kode pairing 8 digit (alternatif scan QR).

FieldTipeWajibKeterangan
phonestringyaNomor internasional tanpa +, contoh: 6281234567890
▸ Contoh input
curl -X POST https://chat.binariscorp.co.id/api/accounts/wa_mw0g9t9arf40m/pair \
  -H "Content-Type: application/json" \
  -d '{"phone":"6281234567890"}'
▸ Response
{
  "ok": true,
  "data": { "code": "AB12CD34", "phone": "6281234567890" }
}

Masukkan kode di HP: WhatsApp → Perangkat Tertaut → Tautkan dengan nomor telepon.

POST /api/accounts/:id/start | /api/accounts/:id/stop

Start ulang / hentikan koneksi akun.

▸ Contoh
curl -X POST https://chat.binariscorp.co.id/api/accounts/wa_mw0g9t9arf40m/start
curl -X POST https://chat.binariscorp.co.id/api/accounts/wa_mw0g9t9arf40m/stop
POST /api/accounts/:id/logout | DELETE /api/accounts/:id

Logout (hapus sesi WA) / hapus akun beserta sesinya.

▸ Contoh
curl -X POST https://chat.binariscorp.co.id/api/accounts/wa_mw0g9t9arf40m/logout
curl -X DELETE https://chat.binariscorp.co.id/api/accounts/wa_mw0g9t9arf40m
GET /api/stats | GET /api/health

Ringkasan (total/online/offline/terkirim) dan health check server.

▸ Contoh
curl https://chat.binariscorp.co.id/api/stats

{
  "ok": true,
  "data": {
    "total": 2, "online": 1, "offline": 1,
    "pending": 0, "sent": 15, "received": 8
  }
}

4. Endpoint Pesan

POST /api/accounts/:id/send

Kirim pesan teks, gambar, PDF, dokumen, video, atau audio. Akun harus online.

FieldTipeWajibKeterangan
tostringyaNomor tujuan: 6281234567890 atau id grup (120363...@g.us)
textstringya*Isi pesan / caption file
mediaobjecttidakLampiran file (lihat bawah)

*wajib diisi jika tidak ada media.

a) Teks saja

▸ Contoh input
curl -X POST https://chat.binariscorp.co.id/api/accounts/wa_mw0g9t9arf40m/send \
  -H "Content-Type: application/json" \
  -d '{
    "to": "6289876543210",
    "text": "Halo, ini pesan dari API"
  }'

b) File via URL (image / PDF / dokumen)

Field mediaTipeKeterangan
urlstringURL file (http/https)
fileNamestringNama file (opsional, ambil dari URL)
mimetypestringContoh: application/pdf (opsional, auto-detect)
▸ Contoh input — kirim PDF
curl -X POST https://chat.binariscorp.co.id/api/accounts/wa_mw0g9t9arf40m/send \
  -H "Content-Type: application/json" \
  -d '{
    "to": "6289876543210",
    "text": "Ini laporannya ya",
    "media": { "url": "https://contoh.com/files/laporan.pdf" }
  }'
▸ Contoh input — kirim gambar
curl -X POST https://chat.binariscorp.co.id/api/accounts/wa_mw0g9t9arf40m/send \
  -H "Content-Type: application/json" \
  -d '{
    "to": "6289876543210",
    "text": "Lihat foto ini",
    "media": { "url": "https://contoh.com/images/foto.jpg" }
  }'

c) File via base64

▸ Contoh input
curl -X POST https://chat.binariscorp.co.id/api/accounts/wa_mw0g9t9arf40m/send \
  -H "Content-Type: application/json" \
  -d '{
    "to": "6289876543210",
    "text": "Dokumen terlampir",
    "media": {
      "base64": "data:application/pdf;base64,JVBERi0xLjQK...",
      "fileName": "laporan.pdf",
      "mimetype": "application/pdf"
    }
  }'

d) Tanpa caption (kirim file saja)

▸ Contoh input
curl -X POST https://chat.binariscorp.co.id/api/accounts/wa_mw0g9t9arf40m/send \
  -H "Content-Type: application/json" \
  -d '{
    "to": "6289876543210",
    "media": { "url": "https://contoh.com/files/bukti.zip" }
  }'

Jenis file otomatis: image/* → pesan gambar · video/* → video · audio/* → audio · lainnya (pdf/doc/xlsx/zip) → dokumen. Maks 64MB.

▸ Response sukses
{
  "ok": true,
  "data": {
    "to": "6289876543210@s.whatsapp.net",
    "sentAt": "2026-11-04T08:00:00.000Z",
    "media": true
  }
}

5. Status Akun

online — terhubung, siap kirim pesan
qr — menunggu scan QR / kode pairing
connecting — sedang menyambung / reconnect
offline — terputus / belum login

Kirim pesan hanya bisa saat status online, selain itu API membalas error 409 — Akun tidak sedang online.

6. Contoh Lengkap (dari nol sampai kirim)

# 1) Buat akun
ID=$(curl -s -X POST https://chat.binariscorp.co.id/api/accounts \
  -H "Content-Type: application/json" \
  -d '{"label":"Sales"}' | grep -o '"id":"[^"]*"' | cut -d'"' -f4)
echo $ID

# 2) Ambil kode pairing
curl -X POST https://chat.binariscorp.co.id/api/accounts/$ID/pair \
  -H "Content-Type: application/json" \
  -d '{"phone":"6281234567890"}'
# → {"data":{"code":"AB12CD34"}} — masukkan kode di HP

# 3) Cek status sampai online
curl https://chat.binariscorp.co.id/api/accounts/$ID

# 4) Kirim teks
curl -X POST https://chat.binariscorp.co.id/api/accounts/$ID/send \
  -H "Content-Type: application/json" \
  -d '{"to":"6289876543210","text":"Halo!"}'

# 5) Kirim PDF
curl -X POST https://chat.binariscorp.co.id/api/accounts/$ID/send \
  -H "Content-Type: application/json" \
  -d '{"to":"6289876543210","text":"Lampiran","media":{"url":"https://contoh.com/laporan.pdf"}}'

WhatsApp API Dashboard — dokumentasi endpoint v1