Lewati ke konten utama

API Cookbook

Ringkasan awam

Halaman ini isinya contoh pakai API yang paling sering: login, bikin SPB, update PO, OTP membership, dan FCM token.

Visual Alur API yang Paling Sering

Sequence End-to-End API (Core)

1) Login API v1 (Sanctum)

curl -X POST 'https://<host>/api/v1/user/login' \
-H 'Content-Type: application/json' \
-d '{"username":"headm","password":"password"}'

Response indikatif:

{
"data": {
"access_token": "1|xxxxx",
"user": {"id": 1, "role": "head_admin"}
}
}

2) Buat SPB dari API (Project)

curl -X POST 'https://<host>/api/v1/project/spb/0001-AJU-SPB(PROJ)I-2026' \
-H 'Authorization: Bearer <token>' \
-H 'Content-Type: application/json' \
-d '{
"delivery_date": "2026-03-10",
"items": [
{"name":"Semen","quantity":50,"unit":"sak","notes":"Type A"}
]
}'

3) Update status PO dari Project/SPV (received)

curl -X POST 'https://<host>/api/v1/project/spb/SPBNO/po/PONO' \
-H 'Authorization: Bearer <token>' \
-F 'status=received' \
-F 'notes=Barang sudah diterima'

4) OTP Request Membership

curl -X POST 'https://<host>/membership/otp/request' \
-H 'Content-Type: application/json' \
-d '{"email":"user@domain.com"}'

5) Simpan FCM Membership

curl -X PATCH 'https://<host>/membership/fcm' \
-H 'Authorization: Bearer <token>' \
-H 'Content-Type: application/json' \
-d '{"token":"fcm-device-token"}'

Quick Visual Summary (Endpoint)

Use caseEndpointMethodAuth
Login/api/v1/user/loginPOSTNo
Buat SPB/api/v1/project/spb/{spbNo}POSTBearer
Update PO status/api/v1/project/spb/{spbNo}/po/{poNo}POST/PATCH (tergantung route)Bearer
OTP request/membership/otp/requestPOSTNo
Simpan FCM/membership/fcmPATCHBearer
Tips implementasi client
  • Simpan token per user-session.
  • Handle 403 untuk pelanggaran role.
  • Untuk endpoint match(POST,PATCH), pastikan role sesuai aksi.

Catatan Verifikasi

  • Status: Partial
  • Scope: Payload login (username vs email) dan prefix URL membership antar environment.
  • Action: Validasi langsung terhadap request class + konfigurasi route di environment target sebelum implementasi client.