Halaman ini berisi contoh kode JavaScript (fetch) untuk setiap endpoint API server
ctech-admin-server. Ganti http://SERVER:PORT dengan alamat server Anda (misal:
http://192.168.1.100:8888).
Content-Type: application/json, kecuali endpoint yang
menerima upload file (gunakan FormData).Authorization: Bearer TOKEN_ANDA./api/*, beberapa response menggunakan format standar
{ status, pesan, data }, namun format lama { message, ... } masih digunakan di beberapa endpoint untuk kompatibilitas.
{
"status": "success",
"pesan": "Berhasil.",
"data": { ... }
}
• Format lama (masih digunakan di banyak endpoint):
{
"message": "Berhasil.",
"data": [...],
...
}
• Error responses bervariasi tergantung endpoint.
/api/usersAmbil semua user (tanpa password)
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/users");
const data = await res.json();
Contoh Response:
[{ "id": 1, "name": "Admin", "email": "[email protected]", "role": "admin", "foto": null }]
/api/users/registerRegistrasi user baru. Email verifikasi akan dikirim.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/users/register", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
name: "John Doe",
email: "[email protected]",
password: "rahasia123"
})
});
Contoh Response:
{ "message": "User berhasil didaftarkan, link verifikasi dikirim ke email.", "id": 5 }
/api/users/loginLogin user, mendapat JWT token.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/users/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email: "[email protected]", password: "rahasia123" })
});
Contoh Response:
{ "status": "success", "pesan": "Login berhasil", "data": { "user": { "id": 1, "name": "John", "email": "[email protected]", "role": "admin" }, "token": "eyJhbGci..." } }
/api/users/verifikasi?token=xxx
Verifikasi email akun (biasanya dari link email).
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/users/verifikasi?token=abc123def456");
Contoh Response:
{ "message": "Akun berhasil diverifikasi" }
/api/users/logoutLogout. Kirim token di header Authorization.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/users/logout", {
method: "POST",
headers: { "Authorization": "Bearer eyJhbGci..." }
});
Contoh Response:
{ "message": "Logout berhasil" }
/api/users/forgot-password
Meminta link reset password.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/users/forgot-password", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ email: "[email protected]" })
});
Contoh Response:
{ "message": "Link reset telah dikirim (simulasi, cek console)" }
/api/users/reset-password
Reset password dengan token yang diterima.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/users/reset-password", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token: "abc123def456", password: "passwordBaru123" })
});
Contoh Response:
{ "message": "Password berhasil direset. Silakan login kembali." }
/api/produk/semuaAmbil semua produk tanpa pagination.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/produk/semua");
const data = await res.json();
Contoh Response:
{ "message": "Berhasil mengambil semua produk.", "total": 150, "data": [{ "produk_id": 1, "produk_nama": "Gula 1kg", "skema_diskon": { "tipe": "bertingkat", "aturan": [{ "min_qty": 5, "persen": 3 }] }, "produk_foto": "http://.../images/produk.webp" }] }
/api/produk?page=1&limit=10
Produk dengan pagination.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/produk?page=1&limit=10");
Contoh Response:
{ "message": "Berhasil.", "meta": { "currentPage": 1, "totalPages": 15, "totalItems": 150 }, "data": [...] }
/api/produk/search?q=gulaCari produk berdasarkan nama/kode.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/produk/search?q=gula");
Contoh Response:
{ "message": "Hasil pencarian produk.", "total": 3, "data": [...] }
/api/produk/:idDetail satu produk.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/produk/5");
Contoh Response:
{ "message": "Detail produk berhasil diambil.", "data": { "produk_id": 5, "produk_nama": "Gula 1kg", "skema_diskon": { "tipe": "nominal", "aturan": [{ "min_qty": 3, "potongan": 2000 }] }, ... } }
/api/produkTambah produk baru. Kode otomatis jika tidak diisi. `skema_diskon` disimpan sebagai JSON ke tabel diskon.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/produk", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
produk_nama: "Gula Pasir 1kg",
produk_satuan: "pcs",
produk_kategori: 1,
produk_stok: 100,
produk_hna: 12000,
produk_ppn: 11,
produk_diskon_beli: 5,
produk_diskon_jual: 2,
produk_harga_modal: 11400,
produk_harga_jual: 14000,
produk_laba: 2600,
produk_keterangan: "Gula pasir premium",
produk_rak: "A1",
produk_expired: "2027-01-01",
skema_diskon: {
tipe: "bertingkat",
aturan: [
{ min_qty: 5, persen: 3 },
{ min_qty: 10, persen: 7 }
]
},
imageUrl: "https://example.com/gula.jpg"
})
});
Contoh Response:
{ "message": "Produk berhasil ditambahkan.", "produk_id": 151, "produk_kode": "PRD0151", "produk_foto": "produk_1710.webp" }
/api/produk/:idUpdate produk (field yang dikirim saja yang berubah), termasuk update atau hapus `skema_diskon`.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/produk/5", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
produk_nama: "Gula Pasir 2kg",
produk_harga_jual: 27000,
skema_diskon: {
tipe: "nominal",
aturan: [{ min_qty: 3, potongan: 2000 }]
}
})
});
Contoh Response:
{ "message": "Produk berhasil diperbarui." }
/api/produk/:idHapus produk beserta foto.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/produk/5", { method: "DELETE" });
Contoh Response:
{ "message": "Produk berhasil dihapus." }
/api/kategoriAmbil semua kategori.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/kategori");
Contoh Response:
[{ "kategori_id": 1, "kategori": "Makanan" }, { "kategori_id": 2, "kategori": "Minuman" }]
/api/kategori/search?q=makanan
Cari kategori.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/kategori/search?q=makanan");
Contoh Response:
{ "message": "Hasil pencarian kategori.", "total": 1, "data": [...] }
/api/kategoriTambah kategori baru.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/kategori", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ kategori: "Elektronik" })
});
Contoh Response:
{ "message": "Kategori berhasil ditambahkan" }
/api/kategori/:idUpdate nama kategori.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/kategori/3", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ kategori: "Elektronik Rumah" })
});
Contoh Response:
{ "message": "Kategori berhasil diperbarui" }
/api/kategori/:idHapus kategori.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/kategori/3", { method: "DELETE" });
Contoh Response:
{ "message": "Kategori berhasil dihapus" }
/api/customerSemua customer.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/customer");
Contoh Response:
{ "message": "Berhasil.", "total": 50, "data": [{ "customer_id": 1, "customer_code": "MLG00001", "customer_nama": "Toko Makmur" }] }
/api/customer/search?q=makmur
Cari customer.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/customer/search?q=makmur");
Contoh Response:
{ "message": "Hasil pencarian customer.", "total": 2, "data": [...] }
/api/customerTambah customer baru. Kode otomatis MLGxxxxx.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/customer", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ customer_nama: "Toko Sejahtera" })
});
Contoh Response:
{ "message": "Customer berhasil ditambahkan", "customer_id": 51, "customer_code": "MLG00051" }
/api/customer/:idUpdate nama customer.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/customer/1", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ customer_nama: "Toko Makmur Jaya" })
});
Contoh Response:
{ "message": "Customer berhasil diperbarui" }
/api/customer/:idHapus customer.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/customer/1", { method: "DELETE" });
Contoh Response:
{ "message": "Customer berhasil dihapus" }
/api/suplierSemua supplier.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/suplier");
Contoh Response:
{ "status": "success", "data": [{ "suplier_id": 1, "suplier_code": "MLG00001", "suplier_nama": "PT Sumber" }] }
/api/suplierTambah supplier baru. Kode otomatis.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/suplier", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ suplier_nama: "PT Baru Jaya" })
});
Contoh Response:
{ "status": "success", "message": "Supplier berhasil ditambahkan", "kode": "MLG00005" }
/api/suplier/:idUpdate supplier.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/suplier/1", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ suplier_code: "MLG00001", suplier_nama: "PT Sumber Makmur" })
});
Contoh Response:
{ "status": "success", "message": "Supplier berhasil diperbarui" }
/api/suplier/:idHapus supplier.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/suplier/1", { method: "DELETE" });
Contoh Response:
{ "status": "success", "message": "Supplier berhasil dihapus" }
/api/penjualanSemua invoice penjualan.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/penjualan");
Contoh Response:
[{ "invoice_id": 1, "invoice_nomor": "MLG-20260318-0001", "invoice_total": 161500, "customer_nama": "Toko A", "salesman_nama": "Budi", "kasir_nama": "Siti" }]
/api/penjualan/:idDetail invoice + daftar item transaksi.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/penjualan/1");
Contoh Response:
{ "invoice_id": 1, "invoice_nomor": "MLG-20260318-0001", ..., "items": [{ "transaksi_produk": 10, "transaksi_harga": 50000, "transaksi_jumlah": 2 }] }
/api/penjualan⭐ Buat penjualan baru. Menggunakan DB Transaction. Nomor invoice otomatis.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/penjualan", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
tanggal: "2026-03-18",
pelanggan: 1,
sub_total: 150000,
diskon: 5000,
ppn: 16500,
total: 161500,
kasir: 1,
salesman: 1,
items: [
{ produk_id: 10, harga: 50000, jumlah: 2, diskon: 0, total: 100000 },
{ produk_id: 15, harga: 50000, jumlah: 1, diskon: 0, total: 50000 }
]
})
});
Contoh Response:
{ "status": "success", "message": "Transaksi berhasil disimpan!", "id": 123, "nomor_invoice": "MLG-20260318-0001" }
/api/penjualan/:idUpdate penjualan. Stok lama dikembalikan, item baru diproses.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/penjualan/123", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
tanggal: "2026-03-18", pelanggan: 1, salesman: 2, kasir: 1,
sub_total: 200000, diskon: 10000, ppn: 21000, total: 211000,
items: [{ produk_id: 10, harga: 50000, jumlah: 4, diskon: 0, total: 200000 }]
})
});
Contoh Response:
{ "status": "success", "message": "Data penjualan berhasil diperbarui." }
/api/penjualan/:idHapus penjualan. Stok dikembalikan.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/penjualan/123", { method: "DELETE" });
Contoh Response:
{ "status": "success", "message": "Penjualan berhasil dihapus." }
/api/pembelianSemua invoice pembelian.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/pembelian");
Contoh Response:
[{ "invoice_beli_id": 1, "invoice_beli_nomor": "PB-001", "suplier_nama": "PT Sumber", "gudang_nama": "Gudang Utama", "invoice_beli_total": 500000 }]
/api/pembelian⭐ Buat pembelian baru. Array item dikirim sebagai array terpisah per field.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/pembelian", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
nomor: "PB-2026-001",
tanggal: "2026-03-18",
suplier_id: 1,
gudang_id: 1,
sub_total: 500000,
diskon: 5,
ppn: 11,
total: 525000,
transaksi_produk: [10, 15],
transaksi_harga: [25000, 30000],
transaksi_jumlah: [10, 10],
transaksi_diskon: [5, 5],
transaksi_total: [237500, 285000],
transaksi_expired: ["2027-01-01", "2027-06-01"]
})
});
Contoh Response:
{ "success": true, "message": "Pembelian berhasil ditambahkan", "id": 5 }
/api/pembelian/:idHapus pembelian. Stok produk dikurangi kembali.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/pembelian/5", { method: "DELETE" });
Contoh Response:
{ "success": true, "message": "Pembelian berhasil dihapus" }
/api/pesananSemua pesanan.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/pesanan");
Contoh Response:
[{ "id": 1, "nomor": "ORD20260318-0001", "user": 3, "total": 150000 }]
/api/pesanan/user/:idPesanan milik satu user beserta isi item.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/pesanan/user/3");
Contoh Response:
[{ "id": 1, "nomor": "ORD20260318-0001", "total": 150000, "items": [{ "id_product": 10, "jumlah_product": 2 }] }]
/api/pesananBuat pesanan baru. Nomor otomatis ORDyyyymmdd-xxxx.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/pesanan", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
user: 3,
total: 150000,
items: [
{ id: 10, jumlah_produk: 2, diskon_produk: 0, harga_produk: 50000, total_harga: 100000 },
{ id: 15, jumlah_produk: 1, diskon_produk: 0, harga_produk: 50000, total_harga: 50000 }
]
})
});
Contoh Response:
{ "message": "Pesanan berhasil ditambahkan", "nomor": "ORD20260318-0001" }
/api/pesanan/:nomorHapus pesanan beserta isinya.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/pesanan/ORD20260318-0001", { method: "DELETE" });
Contoh Response:
{ "message": "Pesanan berhasil dihapus" }
/api/retur?page=1&limit=10
Semua retur dengan pagination.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/retur?page=1&limit=10");
Contoh Response:
{ "message": "Berhasil.", "meta": { "currentPage": 1, "totalPages": 5, "totalItems": 48 }, "data": [...] }
/api/returTambah retur. Stok produk otomatis bertambah.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/retur", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
retur_nomor: "RET-001",
retur_tanggal: "2026-03-18",
retur_dari: 1,
retur_keterangan: "Barang rusak",
items: [
{ produk_id: 10, jumlah_retur: 2, harga_retur: 50000 }
]
})
});
Contoh Response:
{ "message": "Retur berhasil ditambahkan.", "retur_id": 5 }
/api/retur/:idHapus retur. Stok dikurangi kembali.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/retur/5", { method: "DELETE" });
Contoh Response:
{ "message": "Retur berhasil dihapus." }
/api/pegawaiSemua pegawai.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/pegawai");
Contoh Response:
[{ "user_id": 1, "user_nama": "Budi", "user_username": "budi01", "posisi": "admin" }]
/api/pegawai/registerDaftarkan pegawai.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/pegawai/register", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ user_nama: "Dedi", user_username: "dedi01", user_password: "pass123", user_foto: "default.png", posisi: "staff" })
});
Contoh Response:
{ "message": "Pegawai berhasil dibuat.", "user_id": 5 }
/api/pegawai/loginLogin pegawai.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/pegawai/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ user_username: "dedi01", user_password: "pass123" })
});
Contoh Response:
{ "message": "Login berhasil.", "token": "eyJ...", "user": { "user_id": 5, "user_nama": "Dedi" } }
/api/salesmanSemua salesman + token notifikasi.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/salesman");
Contoh Response:
{ "message": "Berhasil.", "total": 10, "data": [{ "salesman_id": 1, "salesman_nama": "Andi" }] }
/api/salesman/registerDaftarkan salesman baru.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/salesman/register", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ salesman_nama: "Eko", salesman_username: "eko01", salesman_password: "pass123" })
});
Contoh Response:
{ "message": "User salesman berhasil dibuat.", "salesman_id": 11 }
/api/salesman/loginLogin salesman.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/salesman/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ salesman_username: "eko01", salesman_password: "pass123" })
});
Contoh Response:
{ "message": "Login berhasil.", "token": "eyJ...", "user": { "salesman_id": 11, "salesman_nama": "Eko", "salesman_foto": "http://.../foto/default.png" } }
/api/salesman/:idUpdate salesman. Bisa upload foto via FormData (multipart/form-data).
Contoh Request (JavaScript fetch):
// MENGGUNAKAN FormData (untuk upload foto):
const formData = new FormData();
formData.append("salesman_nama", "Eko Baru");
formData.append("salesman_foto", fileInput.files[0]); // File dari input
const res = await fetch("http://SERVER:PORT/api/salesman/11", { method: "PUT", body: formData });
Contoh Response:
{ "message": "Data user salesman berhasil diperbarui." }
/api/salesman/ubah-password/:id
Ubah password salesman.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/salesman/ubah-password/11", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ old_password: "pass123", new_password: "newpass", confirm_password: "newpass" })
});
Contoh Response:
{ "message": "Password berhasil diubah." }
/api/ppnSemua data PPN.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/ppn");
Contoh Response:
[{ "ppn_id": 1, "ppn": 11 }]
/api/ppnTambah nilai PPN baru.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/ppn", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ppn: 12 })
});
Contoh Response:
{ "message": "Data PPN berhasil ditambahkan", "ppn_id": 2, "ppn": 12 }
/api/ppn/:idUpdate nilai PPN.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/ppn/1", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ppn: 11 })
});
Contoh Response:
{ "message": "Data PPN berhasil diperbarui" }
/api/perusahaanAmbil data perusahaan (selalu ID=1).
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/perusahaan");
Contoh Response:
{ "message": "Data perusahaan berhasil diambil.", "data": { "id_perusahaan": 1, "nama_perusahaan": "Toko Makmur", "no_perusahaan": "021-123456", "ppn_perusahaan": 11, "logo_url": "http://.../images/logo.png" } }
/api/perusahaanUpdate perusahaan. Upload logo via FormData.
Contoh Request (JavaScript fetch):
// MENGGUNAKAN FormData (untuk upload logo):
const formData = new FormData();
formData.append("nama_perusahaan", "Toko Makmur Jaya");
formData.append("no_perusahaan", "021-654321");
formData.append("ppn_perusahaan", 11);
formData.append("logo_perusahaan", fileInput.files[0]);
const res = await fetch("http://SERVER:PORT/api/perusahaan", { method: "PUT", body: formData });
Contoh Response:
{ "message": "Data perusahaan berhasil diperbarui." }
/api/laporan/penjualan?startDate=2026-03-01&endDate=2026-03-18
Laporan penjualan per periode.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/laporan/penjualan?startDate=2026-03-01&endDate=2026-03-18");
Contoh Response:
{ "summary": { "total_transaksi": 120, "total_penjualan": 50000000, "total_laba_kotor": 8000000 }, "details": [...] }
/api/laporan/pembelian?startDate=..&endDate=..Laporan pembelian per periode.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/laporan/pembelian?startDate=2026-03-01&endDate=2026-03-18");
Contoh Response:
{ "summary": { "total_transaksi": 30, "total_pembelian": 20000000 }, "details": [...] }
/api/laporan/labarugi?startDate=..&endDate=..Laba rugi sederhana.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/laporan/labarugi?startDate=2026-03-01&endDate=2026-03-18");
Contoh Response:
{ "periode": { "mulai": "2026-03-01", "selesai": "2026-03-18" }, "total_laba_kotor": 8000000 }
/api/laporan/penjualan/harian?tanggal=2026-03-18Penjualan harian.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/laporan/penjualan/harian?tanggal=2026-03-18");
Contoh Response:
{ "periode": "2026-03-18", "summary": { "total_transaksi": 15, "total_penjualan": 5000000 }, "details": [...] }
/api/laporan/penjualan/bulanan?tahun=2026&bulan=03Penjualan bulanan.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/laporan/penjualan/bulanan?tahun=2026&bulan=03");
Contoh Response:
{ "periode": { "tahun": 2026, "bulan": "03" }, "laporan_harian": [{ "tanggal": "2026-03-01", "total_transaksi": 10, "total_penjualan": 2000000 }] }
/api/laporan/penjualan/tahunan?tahun=2026Penjualan tahunan.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/laporan/penjualan/tahunan?tahun=2026");
Contoh Response:
{ "periode": { "tahun": 2026 }, "laporan_bulanan": [{ "bulan": 1, "total_transaksi": 300, "total_penjualan": 80000000 }] }
/api/laporan/stokLaporan stok semua produk.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/laporan/stok");
Contoh Response:
{ "message": "Laporan stok produk berhasil diambil.", "total_jenis_produk": 150, "data": [{ "produk_kode": "PRD0001", "produk_nama": "Gula", "produk_stok": 100 }] }
/api/laporan/modalTotal modal inventaris.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/laporan/modal");
Contoh Response:
{ "message": "Laporan total modal.", "data": { "total_item_stok": 5000, "total_modal_investasi": 250000000 } }
/api/groqKirim pertanyaan ke AI (Groq SDK).
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/groq", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ pertanyaan: "Apa alamat perusahaan ctech?" })
});
Contoh Response:
{ "response": "Alamat perusahaan Ctech berada di Kebonagung, Pakisaji, Malang, Jawa Timur." }
/api/pesanAmbil semua data notifikasi dari MySQL.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/pesan");
Contoh Response:
[{ "notifikasi_id": 1, "id_salesman": 1, "idcordova": "abc123", "token": "fcm_token_xxx" }]
/api/pesanSimpan pesan baru ke Firebase Realtime DB.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/pesan", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ title: "Pesanan Baru", body: "Pesanan #0001 telah diterima", type: "order" })
});
Contoh Response:
{ "id": "uuid-xxx", "title": "Pesanan Baru", "message": "Pesan berhasil dibuat." }
/fcmDaftarkan/update token FCM untuk salesman.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/fcm", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
data: { idcordova: "device-abc123", token: "fcm_token_xxx", id_salesman: 1 }
})
});
Contoh Response:
{ "id": 5, "idcordova": "device-abc123", "token": "fcm_token_xxx", "id_salesman": 1, "message": "Token berhasil didaftarkan." }
/fcm/:id_salesmanAmbil semua token FCM milik salesman.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/fcm/1");
Contoh Response:
{ "message": "Data token FCM berhasil diambil.", "total": 2, "data": [...] }
/fcm/:id_salesmanUpdate semua token milik salesman.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/fcm/1", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token: "new_fcm_token" })
});
Contoh Response:
{ "message": "Token FCM berhasil diperbarui.", "data": { "id_salesman": 1, "token": "new_fcm_token", "updated_count": 2 } }
/fcm/:id_salesmanHapus semua token FCM milik salesman.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/fcm/1", { method: "DELETE" });
Contoh Response:
{ "message": "Token FCM berhasil dihapus.", "data": { "id_salesman": 1, "deleted_count": 2 } }
/api/eventsSSE (Server-Sent Events). Gunakan EventSource, bukan fetch.
Contoh Request (JavaScript fetch):
// JANGAN gunakan fetch! Gunakan EventSource:
const eventSource = new EventSource("http://SERVER:PORT/api/events");
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log("Notifikasi:", data);
// data = { id: 1, active: true, message: "Server maintenance", type: "warning" }
};
Contoh Response:
// Data dikirim terus-menerus via stream:
{ "id": 1, "active": true, "message": "Server maintenance jam 22:00", "type": "warning" }
/api/notificationsKirim/broadcast notifikasi SSE ke semua client.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/notifications", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ active: true, message: "Server maintenance jam 22:00", type: "warning" })
});
Contoh Response:
{ "message": "Status notifikasi diperbarui dan disiarkan.", "data": { "id": 1, "active": true, "message": "Server maintenance jam 22:00", "type": "warning" } }
/api/updates/check?version=1.0.0Cek apakah ada update aplikasi baru.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/api/updates/check?version=1.0.0");
Contoh Response:
{ "current_version": "1.1.0", "client_version": "1.0.0", "has_update": true, "updates_count": 1 }
/api/updates/uploadUpload file update (.exe) via FormData.
Contoh Request (JavaScript fetch):
const formData = new FormData();
formData.append("update_file", exeFile);
formData.append("version", "1.1.0");
formData.append("release_notes", "Bug fix dan perbaikan performa");
const res = await fetch("http://SERVER:PORT/api/updates/upload", { method: "POST", body: formData });
Contoh Response:
{ "message": "File update berhasil diunggah.", "data": { "version": "1.1.0", "file": "16789...-app.exe", "download_url": "/api/updates/download/16789...-app.exe" } }
/testTest koneksi & ambil data perusahaan.
Contoh Request (JavaScript fetch):
const res = await fetch("http://SERVER:PORT/test?ipclient=192.168.1.5&aplikasi=mobile");
Contoh Response:
{ "pesan": "berhasil", "data": { "id_perusahaan": 1, "nama_perusahaan": "Toko Makmur", "logo_url": "http://.../images/logo.png" } }
/pesanKirim notifikasi FCM langsung (satu device atau broadcast).
Contoh Request (JavaScript fetch):
// Kirim ke satu device:
const res = await fetch("http://SERVER:PORT/pesan", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
deviceToken: "fcm_token_xxx",
title: "Pesanan Baru",
body: "Ada pesanan masuk #0001",
dataPayload: { orderId: "0001", screen: "order_detail" }
})
});
// Broadcast ke semua:
// body: { broadcast: true, title: "Promo!", body: "Diskon 50%", dataPayload: {} }
Contoh Response:
// Single: { "messageId": "projects/xxx/messages/123", "broadcast": false }
// Broadcast: { "message": "Broadcast selesai dikirim.", "broadcast": true, "total": 50, "success": 48, "failed": 2 }
Dibuat otomatis dari analisis source code router — ctech-admin-server