← Kembali ke Info API

📡 Dokumentasi Lengkap: Cara Kirim Data & Format Response API

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).

📌 Tips Penting:
• Semua POST/PUT kirim data JSON dengan header Content-Type: application/json, kecuali endpoint yang menerima upload file (gunakan FormData).
• Untuk endpoint yang butuh autentikasi, tambahkan header Authorization: Bearer TOKEN_ANDA.
• Khusus endpoint /api/*, beberapa response menggunakan format standar { status, pesan, data }, namun format lama { message, ... } masih digunakan di beberapa endpoint untuk kompatibilitas.
Format Response API:
• Format standar untuk beberapa endpoint:
{
  "status": "success",
  "pesan": "Berhasil.",
  "data": { ... }
}
• Format lama (masih digunakan di banyak endpoint):
{
  "message": "Berhasil.",
  "data": [...],
  ...
}
• Error responses bervariasi tergantung endpoint.

/api/users — Autentikasi & User Admin

GET/api/users

Ambil 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 }]
POST/api/users/register

Registrasi 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 }
POST/api/users/login

Login 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..." } }
GET/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" }
POST/api/users/logout

Logout. 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" }
POST/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)" }
POST/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 — Master Produk

GET/api/produk/semua

Ambil 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" }] }
GET/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": [...] }
GET/api/produk/search?q=gula

Cari 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": [...] }
GET/api/produk/:id

Detail 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 }] }, ... } }
POST/api/produk

Tambah 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" }
PUT/api/produk/:id

Update 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." }
DELETE/api/produk/:id

Hapus 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/kategori — Master Kategori

GET/api/kategori

Ambil 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" }]
GET/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": [...] }
POST/api/kategori

Tambah 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" }
PUT/api/kategori/:id

Update 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" }
DELETE/api/kategori/:id

Hapus kategori.

Contoh Request (JavaScript fetch):

const res = await fetch("http://SERVER:PORT/api/kategori/3", { method: "DELETE" });

Contoh Response:

{ "message": "Kategori berhasil dihapus" }

/api/customer — Master Customer

GET/api/customer

Semua 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" }] }
GET/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": [...] }
POST/api/customer

Tambah 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" }
PUT/api/customer/:id

Update 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" }
DELETE/api/customer/:id

Hapus customer.

Contoh Request (JavaScript fetch):

const res = await fetch("http://SERVER:PORT/api/customer/1", { method: "DELETE" });

Contoh Response:

{ "message": "Customer berhasil dihapus" }

/api/suplier — Master Supplier

GET/api/suplier

Semua 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" }] }
POST/api/suplier

Tambah 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" }
PUT/api/suplier/:id

Update 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" }
DELETE/api/suplier/:id

Hapus 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/penjualan — Transaksi Penjualan (Invoice)

GET/api/penjualan

Semua 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" }]
GET/api/penjualan/:id

Detail 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 }] }
POST/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" }
PUT/api/penjualan/:id

Update 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." }
DELETE/api/penjualan/:id

Hapus 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/pembelian — Transaksi Pembelian (dari Supplier)

GET/api/pembelian

Semua 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 }]
POST/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 }
DELETE/api/pembelian/:id

Hapus 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/pesanan — Pesanan Online

GET/api/pesanan

Semua 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 }]
GET/api/pesanan/user/:id

Pesanan 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 }] }]
POST/api/pesanan

Buat 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" }
DELETE/api/pesanan/:nomor

Hapus 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 — Retur Barang

GET/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": [...] }
POST/api/retur

Tambah 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 }
DELETE/api/retur/:id

Hapus 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/pegawai — User Pegawai

GET/api/pegawai

Semua 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" }]
POST/api/pegawai/register

Daftarkan 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 }
POST/api/pegawai/login

Login 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/salesman — User Salesman

GET/api/salesman

Semua 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" }] }
POST/api/salesman/register

Daftarkan 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 }
POST/api/salesman/login

Login 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" } }
PUT/api/salesman/:id

Update 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." }
PUT/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/ppn — Data PPN

GET/api/ppn

Semua data PPN.

Contoh Request (JavaScript fetch):

const res = await fetch("http://SERVER:PORT/api/ppn");

Contoh Response:

[{ "ppn_id": 1, "ppn": 11 }]
POST/api/ppn

Tambah 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 }
PUT/api/ppn/:id

Update 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/perusahaan — Data Perusahaan

GET/api/perusahaan

Ambil 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" } }
PUT/api/perusahaan

Update 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 — Laporan (Hanya GET, tanpa body)

GET/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": [...] }
GET/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": [...] }
GET/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 }
GET/api/laporan/penjualan/harian?tanggal=2026-03-18

Penjualan 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": [...] }
GET/api/laporan/penjualan/bulanan?tahun=2026&bulan=03

Penjualan 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 }] }
GET/api/laporan/penjualan/tahunan?tahun=2026

Penjualan 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 }] }
GET/api/laporan/stok

Laporan 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 }] }
GET/api/laporan/modal

Total 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/groq — Tanya Jawab AI

POST/api/groq

Kirim 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/pesan — Pesan Firebase Realtime DB

GET/api/pesan

Ambil 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" }]
POST/api/pesan

Simpan 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." }

/fcm — Token FCM Notifikasi

POST/fcm

Daftarkan/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." }
GET/fcm/:id_salesman

Ambil 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": [...] }
PUT/fcm/:id_salesman

Update 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 } }
DELETE/fcm/:id_salesman

Hapus 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 (SSE & Update Aplikasi)

GET/api/events

SSE (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" }
POST/api/notifications

Kirim/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" } }
GET/api/updates/check?version=1.0.0

Cek 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 }
POST/api/updates/upload

Upload 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" } }

Endpoint langsung di server.js

GET/test

Test 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" } }
POST/pesan

Kirim 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

← Info API  |  Kekurangan API →