Complete Flow Documentation & Integration Guide
Version 1.0.1 | RESTful API for fingerprint device management and access control
ZKTeco Device API menyediakan interface RESTful untuk mengelola fingerprint devices, user management, attendance tracking, dan door access control.
| Category | Endpoints | Description |
|---|---|---|
| JWT Auth Users | 2 | Authentication & user registration |
| Attendance | 5 | Attendance records management |
| Device Management | 3 | Device CRUD operations |
| Device Operations | 3 | Device control (restart, info, etc) |
| Door Control | 1 | Door unlock operations |
| User Management | 6 | User sync & management on devices |
| Queue & Cache | 2 | Background jobs & cache management |
Summary: Authenticate user and get JWT tokens
{
"email": "[email protected]",
"password": "danish123"
}
{
"status": true,
"message": "Login successful",
"data": {
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"token_type": "Bearer",
"expires_in": 3600
}
}
{
"status": false,
"message": "Invalid credentials",
"error": {
"code": "INVALID_CREDENTIALS",
"details": "Email atau password salah"
}
}
| Step | Component | Input | Processing | Output | Status |
|---|---|---|---|---|---|
| 1 | Client | email, password | Send POST request | - | - |
| 2 | Validation | Request body | Validate email format | Validated data | 200 / 400 |
| 3 | Database | Find user by email | User object | Found / 404 | |
| 4 | Auth Service | password + hash | bcrypt.compare() | Boolean | Match / 401 |
| 5 | JWT Service | User data | Generate tokens | access + refresh tokens | 200 |
| 6 | Response | Tokens | Format response | JSON response | 200 |
Summary: Register new user (Admin only)
Endpoint ini memerlukan authentication token dengan role "admin"
Header: Authorization: Bearer {admin_access_token}
{
"username": "john_doe",
"email": "[email protected]",
"password": "password123",
"role": "user"
}
{
"status": true,
"message": "User berhasil didaftarkan",
"data": {
"id": 1,
"username": "john_doe",
"email": "[email protected]",
"role": "user"
}
}
| Status | Scenario | Response |
|---|---|---|
| 400 | Validation error (missing fields, invalid email) | Validation error details |
| 401 | No token or invalid token | Unauthorized - Not logged in |
| 403 | User is not admin | Forbidden - Not an admin |
Attendance endpoints untuk mengelola data absensi dari ZKTeco device.
Summary: Get all attendance records (cached)
Summary: Sync attendance from device to database (ASYNC with queue)
// 202 Accepted Response
{
"status": true,
"message": "Sync job queued successfully",
"data": {
"job_id": "sync-device-1-20240205143000",
"device_id": 1,
"status": "queued",
"queued_at": "2024-02-05T14:30:00Z"
}
}
Summary: Create new device configuration
{
"name": "Main Entrance Reader",
"ip": "192.168.1.100",
"port": 4370,
"password": "",
"location": "Building A - Main Entrance",
"serial_number": "ZKT-001-2024"
}
{
"status": true,
"message": "Device registered successfully",
"data": {
"id": 1,
"name": "Main Entrance Reader",
"ip": "192.168.1.100",
"port": 4370,
"location": "Building A - Main Entrance",
"serial_number": "ZKT-001-2024",
"status": "active",
"is_connected": true,
"created_at": "2024-02-05T14:30:00Z"
}
}
| Step | Action | Success | Failure |
|---|---|---|---|
| 1 | Validate request data | Continue | 400 - Validation error |
| 2 | Check IP uniqueness | Continue | 409 - IP already exists |
| 3 | Test TCP connection | Continue | 400 - Cannot reach device |
| 4 | Insert to database | 201 Created | 500 - Database error |
Summary: Get device information and status
Summary: Restart the device
Restarting device akan:
Summary: Add user to device
Summary: Sync users from device to database (ASYNC with queue)
GET /api/v1/queue/stats| User Count | Estimated Time | Processing Method |
|---|---|---|
| 1-100 | ~5-10 seconds | Sync (real-time) |
| 100-1000 | ~1-2 minutes | Async (background) |
| 1000+ | ~5-10 minutes | Async with batching |
Summary: Unlock door remotely
// Success Response
{
"status": true,
"message": "Door unlocked successfully",
"data": {
"device_id": 1,
"unlock_time": "2024-02-05T14:30:00Z",
"unlocked_by": "[email protected]",
"auto_lock_in": 5,
"audit_id": "AUD-20240205-001"
}
}
Summary: Get queue statistics
// Queue Stats Response
{
"status": true,
"data": {
"total_jobs": 1523,
"active": 5,
"waiting": 12,
"completed": 1480,
"failed": 26,
"queues": {
"attendance-sync": {
"active": 2,
"waiting": 5,
"completed": 850
},
"user-sync": {
"active": 3,
"waiting": 7,
"completed": 630
}
},
"last_updated": "2024-02-05T14:30:00Z"
}
}
Summary: Clear all cache
Clearing cache akan:
Bearer {token}| Feature | Strategy | Benefit |
|---|---|---|
| Caching | Redis cache with 5-minute TTL | Reduce DB load, faster response |
| Async Processing | Queue-based background jobs | Non-blocking operations, better UX |
| Batch Operations | Process 100 records/batch | Efficient bulk operations |
| Connection Pooling | Reuse device connections | Reduce connection overhead |
// Standard Error Response Format
{
"status": false,
"message": "Human-readable error message",
"error": {
"code": "ERROR_CODE",
"type": "ErrorType",
"details": "Additional error details or validation errors"
},
"metadata": {
"timestamp": "2024-02-05T14:30:00Z",
"request_id": "req-abc-123",
"api_version": "v1"
}
}