Analytics / Thống kê API
Nội dung Markdown đầy đủ của trang tài liệu.
# Analytics / Thống kê API
Dùng `Authorization: Bearer <ACCESS_TOKEN>` lấy từ [API xác thực](./authentication.md).
- Production: `https://api-partner.pay2s.vn`.
- UAT: `https://api-partner-uat.pay2s.vn`.
**Response Production và UAT hiện chưa đồng nhất.** Các ví dụ Production dưới đây đối chiếu `MetricsController` ngày 11/10/2026, giá trị là minh họa; chưa gọi Production. Mẫu UAT ở cuối trang đã gọi trực tiếp. Không dùng mẫu UAT để suy ra schema Production.
Các API dưới đây dùng GET, tham số ở query string, không gửi JSON body.
## Lịch sử cuộc gọi API
`GET /v1/metrics/calls`
`page` (mặc định 1), `limit` (1–100, mặc định 25), `path`, `status`, `method`. Production lọc path theo chuỗi con; UAT đối chiếu path chính xác.
Response Production:
```json
{
"success": true,
"data": {
"items": [
{
"id": 1,
"request_id": "REQUEST_DEMO",
"method": "GET",
"path": "/v1/banks",
"status_code": 200,
"response_ms": 35,
"ip": "203.0.113.10",
"user_agent": "Merchant backend",
"created_at": "2026-10-11 12:00:00"
}
],
"page": 1,
"limit": 25,
"total": 1
}
}
```
## Nhật ký API
`GET /v1/metrics/logs`
`page`, `limit`. Production trả `data.logs`; UAT trả `data.items` và hỗ trợ thêm bộ lọc như calls.
Response Production:
```json
{
"success": true,
"data": {
"total": 1,
"page": 1,
"limit": 25,
"logs": [
{
"id": 1,
"request_id": "REQUEST_DEMO",
"method": "GET",
"path": "/v1/banks",
"status_code": 200,
"response_ms": 35,
"ip": "203.0.113.10",
"created_at": "2026-10-11 12:00:00"
}
]
}
}
```
## Thống kê theo endpoint
`GET /v1/metrics/endpoints`
Không có tham số bắt buộc. Production trả `path/count/errors`; UAT nhóm theo `method/path`, trả `total/avg_ms`.
Response Production:
```json
{
"success": true,
"data": [
{
"path": "/v1/banks",
"count": 12,
"errors": 1
}
]
}
```
## Thống kê theo kỳ
`GET /v1/metrics/period`
`type`: `day` (mặc định), `week`, `month`. Không dùng `range=daily`. UAT chưa hỗ trợ, Playground mô phỏng. `period` là ngày hoặc số tuần/tháng theo loại đã chọn.
Response Production:
```json
{
"success": true,
"data": {
"type": "day",
"periods": [
{
"period": "2026-10-11",
"total": 12,
"errors": 1,
"avg_response_ms": "35.0000"
}
]
}
}
```
## Thống kê mã HTTP
`GET /v1/metrics/status`
Không có tham số bắt buộc. Production trả `status_code/count`; UAT trả `status_code/total/avg_ms`. Đây là thống kê mã HTTP, không phải health check.
Response Production:
```json
{
"success": true,
"data": [
{
"status_code": 200,
"count": 12
}
]
}
```
## Request và response đối chiếu ngày 11/10/2026
Các mẫu dưới đây giữ cấu trúc trường và kiểu dữ liệu. Khóa, chữ ký, URL phiên đã được thay bằng placeholder; danh sách chỉ giữ tối đa hai phần tử và dữ liệu ảnh/PDF/XML dài được rút gọn. Không sao chép placeholder để gọi API thật.
### Analytics · calls
<div class="doc-api-actions" data-doc-api-actions><a class="try-button" data-doc-playground href="/playground/?api=metrics-calls">Thử API trong Playground ↗</a><a class="try-button experience-button" data-doc-experience hidden>Trải nghiệm ↗</a></div>
**Đã gọi API demo/UAT.**
`GET /v1/metrics/calls`
Tham số path/query (không gửi JSON body):
```json
{
"page": 1,
"limit": 25
}
```
HTTP 200. Response:
```json
{
"success": true,
"data": {
"items": [
{
"id": 96,
"application_id": 2,
"method": "POST",
"path": "/v1/banks/21/delete-confirm",
"status_code": 200,
"response_ms": 123,
"created_at": "2026-10-10 19:19:35"
},
{
"id": 95,
"application_id": 2,
"method": "DELETE",
"path": "/v1/banks/21",
"status_code": 200,
"response_ms": 142,
"created_at": "2026-10-10 19:19:35"
}
],
"page": 1,
"limit": 25,
"total": 92
}
}
```
### Analytics · endpoints
<div class="doc-api-actions" data-doc-api-actions><a class="try-button" data-doc-playground href="/playground/?api=metrics-endpoints">Thử API trong Playground ↗</a><a class="try-button experience-button" data-doc-experience hidden>Trải nghiệm ↗</a></div>
**Đã gọi API demo/UAT.**
`GET /v1/metrics/endpoints`
Tham số path/query (không gửi JSON body):
```json
{}
```
HTTP 200. Response:
```json
{
"success": true,
"data": [
{
"method": "POST",
"path": "/v1/banks",
"total": 5,
"avg_ms": "142"
},
{
"method": "POST",
"path": "/v1/banks/confirm-otp",
"total": 11,
"avg_ms": "126"
}
]
}
```
### Analytics · period
<div class="doc-api-actions" data-doc-api-actions><a class="try-button" data-doc-playground href="/playground/?api=metrics-period">Thử API trong Playground ↗</a><a class="try-button experience-button" data-doc-experience hidden>Trải nghiệm ↗</a></div>
**Đối chiếu mã nguồn backend; giá trị minh họa.** Theo MetricsController.php. UAT trả 501; Playground mô phỏng đúng cấu trúc Production.
`GET /v1/metrics/period`
Tham số path/query (không gửi JSON body):
```json
{
"type": "day"
}
```
HTTP 200. Response:
```json
{
"success": true,
"data": {
"type": "day",
"periods": [
{
"period": "2026-10-11",
"total": 12,
"errors": 1,
"avg_response_ms": "35.0000"
}
]
}
}
```
### Analytics · status
<div class="doc-api-actions" data-doc-api-actions><a class="try-button" data-doc-playground href="/playground/?api=metrics-status">Thử API trong Playground ↗</a><a class="try-button experience-button" data-doc-experience hidden>Trải nghiệm ↗</a></div>
**Đã gọi API demo/UAT.**
`GET /v1/metrics/status`
Tham số path/query (không gửi JSON body):
```json
{}
```
HTTP 200. Response:
```json
{
"success": true,
"data": [
{
"status_code": 409,
"total": 1,
"avg_ms": "131"
},
{
"status_code": 200,
"total": 78,
"avg_ms": "134"
}
]
}
```
### Analytics · logs
<div class="doc-api-actions" data-doc-api-actions><a class="try-button" data-doc-playground href="/playground/?api=metrics-logs">Thử API trong Playground ↗</a><a class="try-button experience-button" data-doc-experience hidden>Trải nghiệm ↗</a></div>
**Đã gọi API demo/UAT.**
`GET /v1/metrics/logs`
Tham số path/query (không gửi JSON body):
```json
{
"page": 1,
"limit": 25
}
```
HTTP 200. Response:
```json
{
"success": true,
"data": {
"items": [
{
"id": 96,
"application_id": 2,
"method": "POST",
"path": "/v1/banks/21/delete-confirm",
"status_code": 200,
"response_ms": 123,
"created_at": "2026-10-10 19:19:35"
},
{
"id": 95,
"application_id": 2,
"method": "DELETE",
"path": "/v1/banks/21",
"status_code": 200,
"response_ms": 142,
"created_at": "2026-10-10 19:19:35"
}
],
"page": 1,
"limit": 25,
"total": 92
}
}
```