Skip to content

Audit Logs API

Audit Logs provide comprehensive user activity tracking across the Merq platform. Every significant action—creating outlets, updating visits, managing users—is automatically logged with full context including who performed the action, what changed, and when it occurred.

Key characteristics:

  • Workspace-scoped — Users can only view logs from their workspace
  • Read-only API — Logs are created automatically by the system; no manual create/update/delete
  • Compliance-ready — Maintains complete audit trail for regulatory requirements
  • Immutable — Once created, logs cannot be modified or deleted

Use cases:

  • Compliance & Auditing — Track who made changes to sensitive data, maintain audit trail for regulatory requirements
  • Troubleshooting — Investigate data inconsistencies, trace when and where changes occurred
  • Activity Monitoring — Monitor user activity patterns, track feature usage
  • Security — Detect unauthorized access attempts, track privilege escalation
FieldTypeDescription
idintegerPrimary key
workspace_idintegerFK to workspaces (scope)
actor_idintegerFK to users (who performed action)
actor_namestringUser name snapshot at time of action
actor_rolestringUser role value at time of action
entity_typestringEntity type (e.g., “outlet”, “visit”, “user”)
entity_idstringID of affected entity (string supports UUID + uint)
entity_namestringEntity name snapshot for display
actionstringAction type (e.g., “created”, “updated”, “deleted”)
old_valuesJSONPrevious state before change (for updates)
new_valuesJSONNew state after change (for creates/updates)
metadataJSONAdditional context (IP address, user agent, etc.)
created_attimestampWhen action occurred
ActionDescription
createdEntity was created
updatedEntity was modified
deletedEntity was removed
approvedSubmission/workflow item approved
rejectedSubmission/workflow item rejected
assignedEntity assigned to user/team
unassignedEntity unassigned from user/team
loginUser authentication
logoutUser session termination
EntityConstant
Usersuser
Outletsoutlet
Teamsteam
Projectsproject
Principalsprincipal
Visitsvisit
Submissionssubmission
Formsform
Productsproduct
Rolesrole
Permissionspermission
Workspacesworkspace
Attendanceattendance
Sales Orderssales_order
MethodEndpointPermissionDescription
GET/office/v1/audit-logsaudit_log.viewList logs (paginated, filtered)
GET/office/v1/audit-logs/:idaudit_log.viewGet log by ID

Note: Audit logs are read-only. Logs are created automatically by the system via handler-level middleware that captures all mutations.

List endpoint accepts these query parameters:

ParamTypeDescriptionExample
pageintegerPage number (default: 1)1
limitintegerItems per page (default: 50)50
keywordstringSearch across text fieldscarrefour
entity_typestringFilter by entity typeoutlet
entity_idstringFilter by entity ID123
actionstringFilter by action typecreated
actor_idintegerFilter by user ID5
date_fromstring (ISO 8601)Start date range2026-03-01T00:00:00Z
date_tostring (ISO 8601)End date range2026-03-05T23:59:59Z

All filters are optional. Multiple filters can be combined.

Request:

GET /office/v1/audit-logs?page=1&limit=20&entity_type=outlet&action=created&date_from=2026-03-01
Authorization: Bearer <token>

Response:

{
"data": {
"data": [
{
"id": 1001,
"workspace_id": 1,
"actor_id": 5,
"actor_name": "John Doe",
"actor_role": "admin",
"entity_type": "outlet",
"entity_id": "123",
"entity_name": "Carrefour Sudirman",
"action": "created",
"old_values": null,
"new_values": {
"name": "Carrefour Sudirman",
"address": "Jl. Sudirman No. 1",
"channel_group_id": 1,
"timezone": "WIB"
},
"metadata": {
"ip": "192.168.1.100",
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)..."
},
"created_at": "2026-03-05T10:30:00Z"
}
],
"meta": {
"page": 1,
"limit": 20,
"total": 150,
"total_pages": 8
}
},
"message": "Success",
"code": "AUDIT_LOG_LIST"
}

Request:

GET /office/v1/audit-logs/1001
Authorization: Bearer <token>

Response:

{
"data": {
"id": 1001,
"workspace_id": 1,
"actor_id": 5,
"actor_name": "John Doe",
"actor_role": "admin",
"entity_type": "outlet",
"entity_id": "123",
"entity_name": "Carrefour Sudirman",
"action": "created",
"old_values": null,
"new_values": {
"name": "Carrefour Sudirman",
"address": "Jl. Sudirman No. 1",
"channel_group_id": 1,
"channel_id": 2,
"account_id": 3,
"timezone": "WIB"
},
"metadata": {
"ip": "192.168.1.100",
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)..."
},
"created_at": "2026-03-05T10:30:00Z"
},
"message": "Success",
"code": "AUDIT_LOG_FOUND"
}

Track who made changes to sensitive data and maintain audit trail for regulatory requirements:

# Get all outlet changes in date range
GET /office/v1/audit-logs?entity_type=outlet&date_from=2026-01-01&date_to=2026-01-31

Export logs for external audit by iterating through all pages.

Investigate data inconsistencies by tracing when and where changes occurred:

# Get all changes to specific outlet
GET /office/v1/audit-logs?entity_type=outlet&entity_id=123

Review old_values and new_values to see exactly what changed.

Monitor user activity patterns and track feature usage:

# Get all actions by specific user
GET /office/v1/audit-logs?actor_id=5

Identify training needs by analyzing which features users access most.

Detect unauthorized access attempts and track privilege escalation:

# Get all login/logout events
GET /office/v1/audit-logs?action=login
GET /office/v1/audit-logs?action=logout

Monitor data export activities and admin-level changes.

All audit log queries are automatically filtered by workspace_id. This ensures:

  • Data isolation — Users can only see logs from their own workspace
  • Multi-tenant security — No cross-workspace data leakage
  • Compliance boundaries — Audit trails stay within workspace jurisdiction

Exception: Super Admin users with multi-workspace access can view logs across all workspaces they have access to.

PermissionDescription
audit_log.viewView audit logs (list + detail)

Permission constant: PermissionKeyAuditLogView

RoleAccess
Super AdminFull access to all workspace logs
AdminFull access to workspace logs
ManagerRead-only access (team-scoped if restricted)
Regular UserNo access (unless explicitly granted)

Permissions are configured in internal/domain/constant.go:

PermissionKeyAuditLogView string = "audit_log.view"

Routes are registered with middleware requiring this permission:

group.Use(middleware.RequirePermission(middleware.PermissionRequirement{
Key: domain.PermissionKeyAuditLogView,
Platform: domain.PlatformMerqAdmin,
AccessLevels: []string{domain.AccessLevelFull, domain.AccessLevelView},
AllowFullUp: true,
}))

Audit logs are created automatically for all mutation operations across the platform:

EntityActions Logged
Outletscreated, updated, deleted
Visitscreated, updated, deleted, assigned, unassigned
Userscreated, updated, deleted, assigned, unassigned
Teamscreated, updated, deleted
Submissionscreated, approved, rejected
Rolescreated, updated, deleted
Permissionscreated, updated, deleted
Workspacescreated, updated, deleted
Attendancecreated, updated, deleted
Sales Orderscreated, updated, deleted
Principalscreated, updated, deleted
Projectscreated, updated, deleted
Productscreated, updated, deleted
Formscreated, updated, deleted
  1. Handler-level middleware captures all mutation requests (POST, PUT, DELETE)
  2. Before transaction commit — Log entry created with old/new values
  3. Metadata enrichment — IP address, user agent, request context added
  4. Denormalization — Actor name, role, and entity name snapshots stored
  5. Transaction commit — Log persisted atomically with the mutation
FieldDescription
ipClient IP address
user_agentBrowser/client user agent string
request_idUnique request identifier (for tracing)
timestampRequest timestamp