driver-device-token

View as Markdown
# Register / Update Driver Device Token Registers or updates the Firebase Cloud Messaging (FCM) device push notification token for the authenticated driver's mobile device (Android or iOS). Used to send dispatch alerts, new ride requests, and system notifications. --- ### Endpoint Overview - **Method:** `POST` - **Route:** `/api/v1/driver/device-token` - **Authentication:** `Bearer Token (Driver JWT)` - **Content-Type:** `application/json` --- ### Request Headers | Header | Type | Required | Description | | --- | --- | --- | --- | | `Authorization` | `string` | **Yes** | Format: `Bearer` | | `Content-Type` | `string` | **Yes** | Must be `application/json` | --- ### Request Body Schema | Field | Data Type | Required | Default | Allowed Values / Constraints | Description | | --- | --- | --- | --- | --- | --- | | `fcm_token` | `string` | **Yes** | — | Min length 1 | Firebase Cloud Messaging push token string | | `platform` | `enum` | **Yes** | — | `"ANDROID""IOS"` | Mobile operating system platform | #### Example Request Body ``` json { "fcm_token": "fcm_eX9aK1L2mN3oP4qR5sT6uV7wX8yZ9aB0c1d2e3f4g5h6", "platform": "ANDROID" } ``` --- ### Response Body Schema (`200 OK`) | Top-Level Key | Data Type | Description | | --- | --- | --- | | `message` | `string` | Confirmation message (`"Driver device token registered successfully"`) | | `device_token` | `object` | Registered/updated device token record in database | #### `device_token` Object Fields | Field | Data Type | Nullable | Allowed Values / Constraints | Description | | --- | --- | --- | --- | --- | | `id` | `string` | No | Prefixed with `ddtok_` | Unique device token record ID | | `driverId` | `string` | No | Prefixed with `drv_` | ID of the driver who owns this token | | `fcm_token` | `string` | No | String | Registered FCM push token | | `platform` | `enum` | No | `"ANDROID"`, `"IOS"` | Device platform | | `is_active` | `boolean` | No | `true`, `false` | Whether token is currently active | | `created_at` | `string` | No | ISO 8601 Timestamp | Registration timestamp | | `updated_at` | `string` | No | ISO 8601 Timestamp | Last update timestamp | --- ### Response Examples #### 1\. `200 OK` — Success (Registered / Updated) ``` json { "message": "Driver device token registered successfully", "device_token": { "id": "ddtok_1a2b3c4d5e", "driverId": "drv_8a7b6c5d4e", "fcm_token": "fcm_eX9aK1L2mN3oP4qR5sT6uV7wX8yZ9aB0c1d2e3f4g5h6", "platform": "ANDROID", "is_active": true, "created_at": "2026-09-21T05:25:00.000Z", "updated_at": "2026-09-21T05:25:00.000Z" } } ``` #### 2\. `400 Bad Request` — Validation Error (Invalid Platform or Missing FCM Token) ``` json { "success": false, "message": "Validation failed: platform: Invalid enum value. Expected 'ANDROID' | 'IOS', received 'WEB'", "errors": [ { "field": "platform", "message": "Invalid enum value. Expected 'ANDROID' | 'IOS', received 'WEB'" } ] } ``` #### 3\. `401 Unauthorized` — Missing / Expired Token / Session Revoked ``` json { "error": "Unauthorized", "message": "Invalid or expired driver access token." } ``` #### 4\. `403 Forbidden` — Account Blocked / Deactivated ``` json { "error": "Forbidden", "message": "Driver account is blocked or deactivated." } ``` #### 5\. `500 Internal Server Error` ``` json { "error": "Failed to register driver device token" } ``` --- ### Status Codes Reference | HTTP Status Code | Condition | | --- | --- | | **`200 OK`** | Device token successfully inserted or refreshed in database. | | **`400 Bad Request`** | Missing `fcm_token` or `platform` is not `"ANDROID"` or `"IOS"`. | | **`401 Unauthorized`** | Missing, invalid, expired token or session revoked. | | **`403 Forbidden`** | Driver account is deactivated or blocked. | | **`500 Internal Server Error`** | Server or database error during token upsert. |

Authentication

AuthorizationBearer

Bearer authentication of the form Bearer <token>, where token is your auth token.