Schema
audit_api_logs Table
Schema and examples for the API call log table.
The audit_api_logs table records outbound HTTP requests to
third-party services so you can correlate them with the data changes
they drove.
Table name is configurable via APIAudit.Table; the default is
audit_api_logs.
Schema
| Column | PostgreSQL | MySQL | SQLite | Description |
|---|---|---|---|---|
id | BIGSERIAL PK | BIGINT UNSIGNED PK | INTEGER | Auto-increment primary key |
service | VARCHAR(100) | VARCHAR(100) | TEXT | Service name (bca, jne) |
endpoint | VARCHAR(500) | VARCHAR(500) | TEXT | API endpoint path |
method | VARCHAR(10) | VARCHAR(10) | TEXT | GET, POST, PUT, DELETE |
status_code | INT | INT | INTEGER | HTTP status code |
request_headers | JSONB | JSON | TEXT | Request headers (redacted) |
response_headers | JSONB | JSON | TEXT | Response headers (redacted) |
request_body | JSONB | JSON | TEXT | Request body (redacted, truncated) |
response_body | JSONB | JSON | TEXT | Response body (redacted, truncated) |
duration_ms | INT | INT | INTEGER | Request duration |
error_message | TEXT | TEXT | TEXT | Error, if failed |
user_id | VARCHAR(100) | VARCHAR(100) | TEXT | Who triggered the call |
metadata | JSONB | JSON | TEXT | Extra context |
transaction_id | VARCHAR(100) | VARCHAR(100) | TEXT | Links to data changes |
created_at | TIMESTAMPTZ | TIMESTAMP | DATETIME | When the call was made |
Indexes
All dialects create these indexes:
idx_<table>_service (service, created_at)
idx_<table>_status (status_code)
idx_<table>_user (user_id)
idx_<table>_created (created_at)
idx_<table>_transaction (transaction_id)Go Struct
Go
type AuditAPILog struct {
ID uint64 `json:"id"`
Service string `json:"service"`
Endpoint string `json:"endpoint"`
Method string `json:"method"`
StatusCode int `json:"status_code"`
RequestHeaders json.RawMessage `json:"request_headers,omitempty"`
ResponseHeaders json.RawMessage `json:"response_headers,omitempty"`
RequestBody json.RawMessage `json:"request_body,omitempty"`
ResponseBody json.RawMessage `json:"response_body,omitempty"`
DurationMs int `json:"duration_ms"`
ErrorMessage string `json:"error_message,omitempty"`
UserID string `json:"user_id,omitempty"`
Metadata json.RawMessage `json:"metadata,omitempty"`
TransactionID string `json:"transaction_id,omitempty"`
CreatedAt time.Time `json:"created_at"`
}Go snippet
RequestHeaders, ResponseHeaders, RequestBody, ResponseBody,
and Metadata are json.RawMessage — decode them into whatever
shape your caller expects.
Upgrading from v1.0.x
response_headers was added in v1.1.0. AutoMigrate uses
CREATE TABLE IF NOT EXISTS, so existing deployments must add the
column manually before upgrading:
SQL
-- PostgreSQL
ALTER TABLE audit_api_logs ADD COLUMN response_headers JSONB;
-- MySQL
ALTER TABLE audit_api_logs ADD COLUMN response_headers JSON;
-- SQLite
ALTER TABLE audit_api_logs ADD COLUMN response_headers TEXT;SQL snippet
Fresh installs running v1.1.0+ get the column automatically.
Example Records
Payment API call
JSON
{
"service": "bca",
"endpoint": "/v1/transfer",
"method": "POST",
"status_code": 200,
"request_headers": {
"Authorization": "***REDACTED***",
"Content-Type": "application/json"
},
"request_body": { "amount": 100000, "account": "1234567890" },
"response_body": { "reference": "BCA-TRX-42", "status": "success" },
"duration_ms": 842,
"user_id": "admin-1",
"transaction_id": "20260413T090000-a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
"created_at": "2026-04-13T09:00:00Z"
}JSON snippet
Truncated response
JSON
{
"service": "jne",
"endpoint": "/v2/tracking",
"method": "GET",
"status_code": 200,
"response_body": {
"_truncated": true,
"original_size": 128512,
"preview": "{\"status\":\"in_transit\",\"history\":["
},
"duration_ms": 230,
"transaction_id": "20260413T090000-a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6",
"created_at": "2026-04-13T09:00:01Z"
}JSON snippet