Pengguna API
Dokumentasi API endpoints untuk manajemen pengguna.
Base URL
/api/v1/pengguna
Authentication
Semua endpoints memerlukan authentication header:
Authorization: xxxTOKENxxxxx
Endpoints
List Pengguna
Mendapatkan daftar pengguna dengan pagination dan filter.
Endpoint: GET /api/v1/pengguna
Query Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
page | int | 1 | Halaman yang diminta |
per_page | int | 10 | Jumlah data per halaman |
filter | string | - | Filter data (format: column,operator,value) |
Filter Operators:
| Operator | Description | Example |
|---|---|---|
= | Equal | nama,=,John |
like | Contains (case sensitive) | nama,like,John |
ilike | Contains (case insensitive) | nama,ilike,john |
> | Greater than | created_at,>,2024-01-01 |
< | Less than | created_at,<,2024-12-31 |
>= | Greater than or equal | level,>=,5 |
<= | Less than or equal | level,<=,10 |
<> | Not equal | status,<>,inactive |
in | In list | `tipe_pegawai,in,pns |
Response Success (200):
{
"code": 200,
"status": true,
"message": "Success",
"data": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"no_pegawai": "123456",
"nama": "John Doe",
"email": "john@example.com",
"tipe_pegawai": "pns",
"hak_akses_id": "admin",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z"
}
],
"info": {
"total": 100,
"per_page": 10,
"page": 1,
"pages": 10,
"count": 10
}
}
Example Requests:
# Basic
curl -X GET "http://localhost:8000/api/v1/pengguna" \
-H "Authorization: xxxTOKENxxxxx"
# With pagination
curl -X GET "http://localhost:8000/api/v1/pengguna?page=2&per_page=20" \
-H "Authorization: xxxTOKENxxxxx"
# With filter
curl -X GET "http://localhost:8000/api/v1/pengguna?filter=nama,ilike,john" \
-H "Authorization: xxxTOKENxxxxx"
# Multiple filters
curl -X GET "http://localhost:8000/api/v1/pengguna?filter=tipe_pegawai,=,pns;nama,ilike,john" \
-H "Authorization: xxxTOKENxxxxx"
Get Pengguna by ID
Mendapatkan detail pengguna berdasarkan ID.
Endpoint: GET /api/v1/pengguna/:id
Path Parameters:
| Parameter | Type | Description |
|---|---|---|
id | string (UUID) | ID pengguna |
Response Success (200):
{
"code": 200,
"status": true,
"message": "Success",
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"no_pegawai": "123456",
"nama": "John Doe",
"email": "john@example.com",
"tipe_pegawai": "pns",
"hak_akses_id": "admin",
"hak_akses": {
"id": "admin",
"nama": "Administrator"
},
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z"
}
}
Response Error (404):
{
"code": 404,
"status": false,
"message": "Pengguna tidak ditemukan"
}
Example Request:
curl -X GET "http://localhost:8000/api/v1/pengguna/550e8400-e29b-41d4-a716-446655440000" \
-H "Authorization: xxxTOKENxxxxx"
Create Pengguna
Membuat pengguna baru.
Endpoint: POST /api/v1/pengguna
Request Body:
{
"no_pegawai": "string",
"nama": "string",
"email": "string",
"kata_sandi": "string",
"tipe_pegawai": "string",
"hak_akses_id": "string"
}
| Field | Type | Required | Description |
|---|---|---|---|
no_pegawai | string | ✅ | Nomor pegawai (unique) |
nama | string | ✅ | Nama lengkap |
email | string | ✅ | Email (unique) |
kata_sandi | string | ✅ | Password (harus memenuhi kriteria) |
tipe_pegawai | string | ✅ | Tipe pegawai: pns, pjlp, bpjs |
hak_akses_id | string | ✅ | ID hak akses |
Response Success (201):
{
"code": 201,
"status": true,
"message": "Pengguna berhasil dibuat",
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"no_pegawai": "123456",
"nama": "John Doe"
}
}
Response Error (400):
{
"code": 400,
"status": false,
"message": "No pegawai sudah terdaftar"
}
Example Request:
curl -X POST "http://localhost:8000/api/v1/pengguna" \
-H "Content-Type: application/json" \
-H "Authorization: xxxTOKENxxxxx" \
-d '{
"no_pegawai": "123456",
"nama": "John Doe",
"email": "john@example.com",
"kata_sandi": "Password1!",
"tipe_pegawai": "pns",
"hak_akses_id": "staff"
}'
Update Pengguna
Mengupdate data pengguna.
Endpoint: PUT /api/v1/pengguna/:id
Path Parameters:
| Parameter | Type | Description |
|---|---|---|
id | string (UUID) | ID pengguna |
Request Body:
{
"nama": "string",
"email": "string",
"tipe_pegawai": "string",
"hak_akses_id": "string"
}
| Field | Type | Required | Description |
|---|---|---|---|
nama | string | ❌ | Nama lengkap |
email | string | ❌ | |
tipe_pegawai | string | ❌ | Tipe pegawai |
hak_akses_id | string | ❌ | ID hak akses |
Response Success (200):
{
"code": 200,
"status": true,
"message": "Pengguna berhasil diupdate",
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"no_pegawai": "123456",
"nama": "John Doe Updated"
}
}
Example Request:
curl -X PUT "http://localhost:8000/api/v1/pengguna/550e8400-e29b-41d4-a716-446655440000" \
-H "Content-Type: application/json" \
-H "Authorization: xxxTOKENxxxxx" \
-d '{
"nama": "John Doe Updated"
}'
Delete Pengguna
Menghapus pengguna.
Endpoint: DELETE /api/v1/pengguna/:id
Path Parameters:
| Parameter | Type | Description |
|---|---|---|
id | string (UUID) | ID pengguna |
Response Success (200):
{
"code": 200,
"status": true,
"message": "Pengguna berhasil dihapus"
}
Example Request:
curl -X DELETE "http://localhost:8000/api/v1/pengguna/550e8400-e29b-41d4-a716-446655440000" \
-H "Authorization: xxxTOKENxxxxx"
Reset Password
Reset password pengguna (admin only).
Endpoint: POST /api/v1/pengguna/:id/reset-password
Path Parameters:
| Parameter | Type | Description |
|---|---|---|
id | string (UUID) | ID pengguna |
Request Body:
{
"kata_sandi": "string"
}
Response Success (200):
{
"code": 200,
"status": true,
"message": "Password berhasil direset"
}
Example Request:
curl -X POST "http://localhost:8000/api/v1/pengguna/550e8400-e29b-41d4-a716-446655440000/reset-password" \
-H "Content-Type: application/json" \
-H "Authorization: xxxADMIN_TOKENxxxxx" \
-d '{
"kata_sandi": "NewPassword1!"
}'
Update Hak Akses
Update hak akses pengguna.
Endpoint: PUT /api/v1/pengguna/:id/hak-akses
Request Body:
{
"hak_akses_id": "string"
}
Response Success (200):
{
"code": 200,
"status": true,
"message": "Hak akses berhasil diupdate"
}
Example Request:
curl -X PUT "http://localhost:8000/api/v1/pengguna/550e8400-e29b-41d4-a716-446655440000/hak-akses" \
-H "Content-Type: application/json" \
-H "Authorization: xxxTOKENxxxxx" \
-d '{
"hak_akses_id": "admin"
}'
Filter Examples
Filter by Name (Case Insensitive)
GET /api/v1/pengguna?filter=nama,ilike,john
Filter by Tipe Pegawai
GET /api/v1/pengguna?filter=tipe_pegawai,=,pns
Filter Multiple Values
GET /api/v1/pengguna?filter=tipe_pegawai,in,pns|pjlp
Multiple Filters
GET /api/v1/pengguna?filter=tipe_pegawai,=,pns;nama,ilike,john
Filter by Date
GET /api/v1/pengguna?filter=created_at,>,2024-01-01