> ## Documentation Index
> Fetch the complete documentation index at: https://internal.mechzie.in/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Emergency Contacts

> Store up to 2 emergency contacts per user for safety during roadside assistance

## Overview

Customers can save up to **2 emergency contacts** in their profile. These contacts are available for safety purposes during active jobs — the app can notify them or display quick-dial options when the customer is stranded.

## Endpoints

### Upsert Emergency Contacts

Replace all contacts for the authenticated user. Sends an array of 1–2 contacts. Previous contacts are deleted.

```bash theme={null}
PUT /api/v1/users/me/emergency-contacts
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json
```

```json theme={null}
{
  "contacts": [
    {
      "name": "Mom",
      "phone": "+919876543210",
      "relationship": "mother"
    },
    {
      "name": "Dad",
      "phone": "+919876543211",
      "relationship": "father"
    }
  ]
}
```

**Response (200):**

```json theme={null}
{
  "data": [
    {
      "id": "uuid",
      "user_id": "uuid",
      "name": "Mom",
      "phone": "+919876543210",
      "relationship": "mother",
      "sort_order": 0,
      "created_at": "2026-08-04T10:00:00.000Z",
      "updated_at": "2026-08-04T10:00:00.000Z"
    },
    {
      "id": "uuid",
      "user_id": "uuid",
      "name": "Dad",
      "phone": "+919876543211",
      "relationship": "father",
      "sort_order": 1,
      "created_at": "2026-08-04T10:00:00.000Z",
      "updated_at": "2026-08-04T10:00:00.000Z"
    }
  ]
}
```

### List Emergency Contacts

```bash theme={null}
GET /api/v1/users/me/emergency-contacts
Authorization: Bearer ACCESS_TOKEN
```

**Response (200):**

```json theme={null}
{
  "data": [
    {
      "id": "uuid",
      "user_id": "uuid",
      "name": "Mom",
      "phone": "+919876543210",
      "relationship": "mother",
      "sort_order": 0,
      "created_at": "2026-08-04T10:00:00.000Z",
      "updated_at": "2026-08-04T10:00:00.000Z"
    }
  ]
}
```

## Validation Rules

| Field            | Rule                                 |
| ---------------- | ------------------------------------ |
| `name`           | Required, 1–100 characters           |
| `phone`          | Required, must match `+91XXXXXXXXXX` |
| `relationship`   | Optional, max 50 characters          |
| `contacts` array | 1–2 items                            |

<Warning>
  Calling PUT replaces **all** existing contacts. To remove all contacts, send an empty array (which will return a validation error — minimum 1 required). To delete all, the user must keep at least one or the app should handle the empty state gracefully.
</Warning>

## Flutter Integration

```dart theme={null}
// Save emergency contacts
await http.put(
  Uri.parse('$baseUrl/api/v1/users/me/emergency-contacts'),
  headers: {
    'Authorization': 'Bearer $accessToken',
    'Content-Type': 'application/json',
  },
  body: jsonEncode({
    'contacts': [
      {'name': 'Mom', 'phone': '+919876543210', 'relationship': 'mother'},
    ],
  }),
);

// Fetch contacts
final response = await http.get(
  Uri.parse('$baseUrl/api/v1/users/me/emergency-contacts'),
  headers: {'Authorization': 'Bearer $accessToken'},
);
```
