# Query Report Data

> Execute a report query with selected fields and filters.

Source: https://docs.fleetwork.vn/en/reports/reports-query

**POST** `https://live.fleetwork.vn/api/v1/workspace/reports/query`

## Supported Report Types

| `reportType`      | Supported Modes       | Description                             |
| ----------------- | --------------------- | --------------------------------------- |
| `timeline`        | `by_user`             | Task timeline grouped by driver         |
| `time-allocation` | `by_user`, `by_place` | Time spent on tasks per driver or place |
| `statistics`      | `by_user`             | Aggregated performance stats            |
| `job-report`      | `by_user`, `by_place` | Detailed job and task breakdown         |
| `mileage-report`  | `by_user`             | Distance and mileage per driver         |

## Request Body

| Field        | Type     | Required     | Description                                                                              |
| ------------ | -------- | ------------ | ---------------------------------------------------------------------------------------- |
| `reportType` | string   | **Required** | See table above                                                                          |
| `fromTime`   | long     | **Required** | Start time as Unix timestamp (ms)                                                        |
| `toTime`     | long     | **Required** | End time as Unix timestamp (ms)                                                          |
| `mode`       | string   | Optional     | `by_user` (default) or `by_place`                                                        |
| `fields`     | string[] | Optional     | Fields to include — get available fields from [Get Schema](https://docs.fleetwork.vn/en/reports/reports-schema) |
| `userId`     | UUID     | Optional     | Filter by specific user/driver                                                           |
| `placeId`    | UUID     | Optional     | Filter by specific place                                                                 |

```json
{
  "reportType": "job-report",
  "mode": "by_user",
  "fromTime": 1713139200000,
  "toTime": 1713225600000,
  "fields": ["taskName", "status", "completedAt", "driverName"]
}
```

## Example

### Request

```bash
curl -X POST \
  "https://live.fleetwork.vn/api/v1/workspace/reports/query" \
  -H "API-KEY: <your-key>" \
  -H "Content-Type: application/json" \
  -d '{"reportType":"job-report","fromTime":1713139200000,"toTime":1713225600000,"fields":["taskName","status","completedAt"]}'
```

### Response

```json
{
  "code": "OK",
  "message": null,
  "data": {
    "reportType": "job-report",
    "mode": "by_user",
    "total": 87,
    "rows": [
      {
        "taskName": "Deliver package #1",
        "status": 4,
        "completedAt": 1713225600000
      }
    ]
  }
}
```

The `rows` field contains dynamic key-value pairs based on the `fields` requested.
