# Dokumentasi API : WA Gateway

Kirim dan terima pesan WhatsApp lewat REST API, satu API Key per device.

Semua endpoint REST API publik diakses lewat `https://api.jarswa.com`.
Untuk mengelola akun, device, dan paket kuota, gunakan dashboard di
`https://jarswa.com`.

---

## Autentikasi

Tiap device punya **API Key** sendiri (lihat di halaman Device pada dashboard,
tombol "API Key"). Sertakan di setiap request lewat header berikut:

```
Authorization: Bearer {api_key_device}
```

Kalau kuota pesan device kamu habis, endpoint kirim pesan akan menolak
request dengan status `402 Payment Required`. Beli/tambah kuota lewat
dashboard untuk device tersebut untuk melanjutkan.

---

## Kirim Pesan

**POST** `https://api.jarswa.com/send-message`

| Field | Tipe | Keterangan |
|---|---|---|
| `to` | string | Nomor tujuan, format `62812xxxxxxx` |
| `text` | string | Isi pesan |

```bash
curl -X POST https://api.jarswa.com/send-message \
  -H "Authorization: Bearer wagw_live_xxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"to":"6281234567890","text":"Halo dari WA Gateway!"}'
```

Response sukses:
```json
{ "success": true, "remainingQuota": 4899 }
```

---

## Status Device

**GET** `https://api.jarswa.com/device-status`

```bash
curl https://api.jarswa.com/device-status \
  -H "Authorization: Bearer wagw_live_xxxxxxxx"
```

```json
{ "success": true, "status": "connected" }
```

---

## Ambil QR

**GET** `https://api.jarswa.com/qr`

Dipakai kalau kamu mau tampilkan ulang QR code di sistem sendiri (di luar
dashboard WA Gateway).

```bash
curl https://api.jarswa.com/qr \
  -H "Authorization: Bearer wagw_live_xxxxxxxx"
```

---

## Cek Kuota

**GET** `https://api.jarswa.com/quota`

```bash
curl https://api.jarswa.com/quota \
  -H "Authorization: Bearer wagw_live_xxxxxxxx"
```

```json
{ "success": true, "remaining": 4899, "nearestExpiry": "2026-08-12T00:00:00.000Z" }
```

---

## Riwayat Pesan

**GET** `https://api.jarswa.com/message-history`

```bash
curl https://api.jarswa.com/message-history \
  -H "Authorization: Bearer wagw_live_xxxxxxxx"
```

---

## Webhook Pesan Masuk

Kalau kamu isi **Webhook URL** di pengaturan device pada dashboard, setiap
pesan masuk akan otomatis di-*forward* ke URL itu lewat `POST`, format JSON:

```json
{
  "deviceId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "from": "6281234567890@s.whatsapp.net",
  "type": "conversation",
  "body": "Halo, ini pesan masuk",
  "pushName": "Nama Pengirim",
  "timestamp": 1755000000000
}
```

Catatan: forward webhook hanya terjadi untuk pesan personal/grup sesuai
toggle "Personal"/"Group" yang diaktifkan pada device tersebut.

---

## Format Error

Semua error dari API mengikuti format yang sama:

```json
{ "success": false, "message": "Penjelasan error dalam Bahasa Indonesia" }
```

| Kode | Arti |
|---|---|
| 401 | API Key tidak valid / tidak disertakan |
| 402 | Kuota pesan habis |
| 404 | Device tidak ditemukan |
| 409 | Device belum terhubung (belum scan QR) |
| 429 | Batas maksimal device tercapai |

---

© WA Gateway, Jarswa by PT Jars Pedia Technology
