
--------------------------------------------
POSTMAN TEST DATA FOR MALI PLATFORM
--------------------------------------------

Before using these Postman examples, ensure your Django application is running and you have a Super Admin user created.

**Important Setup Steps (Django Admin):**

1.  **Access Django Admin:**
    *   Start your Django development server: `./venv/bin/python manage.py runserver`
    *   Go to `http://127.0.0.1:8000/admin/` in your browser.
    *   Log in with your Super Admin credentials.

2.  **Create a Tenant:**
    *   In the Django admin, navigate to `Core -> Tenants`.
    *   Click "Add Tenant".
    *   Give it a name (e.g., "CoffeeCo").
    *   Save.

3.  **Create a Device:**
    *   In the Django admin, navigate to `Core -> Devices`.
    *   Click "Add Device".
    *   Select the `Tenant` you just created.
    *   Give the device a `Name` (e.g., "VendingMachine001").
    *   Generate a unique `API Key` (e.g., `your_secret_api_key_123`). This is crucial for authentication.
    *   Set `Coffee limit per refill` and `Tea limit per refill` (e.g., 100 for both).
    *   Set initial `Coffee dispense count` and `Tea dispense count` to 0.
    *   Set `Water level` and `Temperature` as desired.
    *   Set `Status` to `IDLE`.
    *   Save.

    **Make sure to copy the `API Key` you assigned to the device, as you'll need it for the Postman requests below.**

--------------------------------------------
POSTMAN REQUEST EXAMPLES
--------------------------------------------

Replace `<your_domain>` with your Django server's address (e.g., `127.0.0.1:8000`).
Replace `<your_device_api_key>` with the API Key you generated in the Django admin.

---

### 1. Send Device Telemetry (POST Request)

This request sends updated sensor data and dispense counts from the device to the backend.

**HTTP Method:** `POST`
**URL:** `http://<your_domain>/api/device/telemetry/`
**Headers:**
`X-API-Key: <your_device_api_key>`
`Content-Type: application/json`
**Body (Raw JSON):**
```json
{
    "coffee_dispense_count": 5,
    "tea_dispense_count": 2,
    "water_level": 75,
    "temperature": 90.1,
    "status": "DISPENSING"
}
```

---

### 2. Fetch Device Configuration (GET Request)

This request retrieves the current configuration and status for the device from the backend.

**HTTP Method:** `GET`
**URL:** `http://<your_domain>/api/device/configuration/`
**Headers:**
`X-API-Key: <your_device_api_key>`

---

### 3. Reset Device Counters (Dashboard Action - GET Request)

This is a **dashboard action**, not a device API call. It's triggered by an authenticated Admin/Super Admin user in the browser to reset dispense counters.
You can test this by logging into the Django admin, navigating to your dashboard (`http://127.0.0.1:8000/api/dashboard/`), and clicking "Reset Counters" next to a device.

If you *were* to simulate this directly (not recommended for actual use due to CSRF protection and session requirements), it would look something like this, but you would need to handle session cookies and CSRF tokens:

**HTTP Method:** `GET` (or POST with CSRF)
**URL:** `http://<your_domain>/api/device/<your_device_id>/reset/`
(Replace `<your_device_id>` with the UUID of your device, found in the Django admin URL when editing the device or on the dashboard.)
**Headers:** (Requires authenticated session cookies and CSRF token)

This is primarily for demonstrating the API calls from the ESP32 device's perspective.
