# Lawneu Legal Requests API

Base URL:

```text
https://page.law.indias.cloud/api/v1
```

Endpoint:

```text
/legal_requests.php
```

## Auth

Public clients can create a legal request without a master key.

Admin/list/read/accept actions require one of:

```text
X-Master-Key: YOUR_MASTER_KEY
```

```text
Authorization: Bearer YOUR_MASTER_KEY
```

Advocate-scoped access can also use:

```text
X-API-KEY: admin_secret_key
```

## Create Legal Request

Client-side public submit. Client mobile and advocate mobile are different fields.

```bash
curl -X POST "https://page.law.indias.cloud/api/v1/legal_requests.php?action=create" \
  -H "Content-Type: application/json" \
  -d '{"advocate_mobile":"919999999999","client_name":"Ravi Kumar","client_mobile":"918888888888","client_email":"client@example.com","client_country":"India","client_state":"Delhi","client_city":"New Delhi","legal_issue":"Property dispute","details":"Need help reviewing property documents."}'
```

Required fields:

| Field | Required | Notes |
| --- | --- | --- |
| `advocate_mobile` | yes | Registered mobile number of the advocate receiving the request. |
| `client_name` | yes | Client name. |
| `client_mobile` | yes | Client mobile number. |
| `legal_issue` | yes | Short issue/category text. |
| `client_email` | no | Used for email notification/reply when available. |
| `client_country` | no | Stored for future country filter. |
| `client_state` | no | Stored for future state filter. |
| `client_city` | no | Stored for future city filter. |
| `details` | no | Full client message/details. |

Example response:

```json
{
  "success": true,
  "message": "Legal request submitted successfully.",
  "request_id": 12,
  "status": "pending",
  "email_sent": true,
  "email_error": ""
}
```

## List Legal Requests

Master can list all requests:

```bash
curl "https://page.law.indias.cloud/api/v1/legal_requests.php?action=list" \
  -H "X-Master-Key: YOUR_MASTER_KEY"
```

Advocate-scoped list by registered mobile:

```bash
curl "https://page.law.indias.cloud/api/v1/legal_requests.php?action=list&advocate_mobile=919999999999" \
  -H "X-API-KEY: admin_secret_key"
```

Response:

```json
{
  "success": true,
  "data": [
    {
      "id": 12,
      "advocate_id": 1,
      "advocate_mobile": "9999999999",
      "client_name": "Ravi Kumar",
      "client_mobile": "8888888888",
      "client_country": "India",
      "client_state": "Delhi",
      "client_city": "New Delhi",
      "legal_issue": "Property dispute",
      "status": "pending"
    }
  ]
}
```

## Read Legal Request

Master read:

```bash
curl "https://page.law.indias.cloud/api/v1/legal_requests.php?action=read&request_id=12" \
  -H "X-Master-Key: YOUR_MASTER_KEY"
```

Advocate read:

```bash
curl "https://page.law.indias.cloud/api/v1/legal_requests.php?action=read&request_id=12&advocate_mobile=919999999999" \
  -H "X-API-KEY: admin_secret_key"
```

## Accept Legal Request

Advocate accepts with registered mobile number. The API verifies the request belongs to that advocate.

```bash
curl -X POST "https://page.law.indias.cloud/api/v1/legal_requests.php?action=accept" \
  -H "X-Master-Key: YOUR_MASTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"request_id":12,"advocate_mobile":"919999999999","advocate_note":"Accepted. Please share documents before the call."}'
```

Aliases accepted:

```text
id        -> request_id
note      -> advocate_note
message   -> details, only while creating
```

Example response:

```json
{
  "success": true,
  "message": "Legal request accepted successfully.",
  "request_id": 12,
  "status": "accepted",
  "accepted_by_name": "Advocate Name",
  "email_sent": true,
  "email_error": ""
}
```

## Status Values

```text
pending
accepted
```

## Notes

- `create` is public for client-side website/app forms.
- `list`, `read`, and `accept` require master/admin authentication.
- Mobile numbers are normalized server-side, so `+91 99999 99999` and `919999999999` match the same registered advocate.
- Location fields are stored separately as `client_country`, `client_state`, and `client_city` for future filtering.
