Smart Energy Platform API Documentation

Version: 1.0 — Base URL: https://bareq.site

Authentication

All endpoints require the following headers:

Content-Type: application/json
x-api-key: YOUR_API_KEY

Building Management APIs

Create Building

POST/api/buildings

Request Body

{
  "name": "Test Building",
  "address": "124 Main St"
}

Example Response

{
  "message": "Created",
  "building": {
    "_id": "187e320f874f499a1a5dd7e3",
    "name": "Test Building",
    "address": "124 Main St",
    "createdBy": "187a54aeb05e05a266b12333",
    "__v": 0
  }
}

Delete Building

DELETE/api/buildings

Request Body

{
  "id": "487d64c9874f499a1a5dd133"
}

Example Response

{ "message": "Deleted" }

Fetch All Buildings

GET/api/buildings

Example Response

{
  "buildings": [
    {
      "_id": "287d63a2874f499a1a5dd145",
      "name": "Updated Building",
      "address": "456 New Address",
      "createdBy": "587a54aeb05e05a266b12123",
      "__v": 0
    }
  ]
}

Update Building

PUT/api/buildings

Request Body

{
  "id": "187d63a2874f499a1a5dd234",
  "name": "Updated Building",
  "address": "456 New Address"
}

Example Response

{
  "message": "Updated",
  "building": {
    "_id": "287d63a2874f499a1a5dd125",
    "name": "Updated Building",
    "address": "456 New Address",
    "createdBy": "337a54aeb05e05a266b1sd4e",
    "__v": 0
  }
}

Apartment Management APIs

Create Apartment

POST/api/apartments

Request Body

{
  "name": "Apartment 101",
  "buildingId": "s47d63a2874f499a1a5dd44t",
  "deviceId": "",
  "deviceName": ""
}

Example Response

{
  "success": true,
  "apartment": {
    "_id": "237e39c0874f499a1a5dd44rt",
    "buildingId": "337d63a2874f499a1a5dd744",
    "name": "Apartment 101",
    "deviceId": null,
    "deviceName": null,
    "__v": 0
  }
}

Fetch Apartments by Building ID

GET/api/apartments?buildingId=BUILDING_ID

Example Response

{
  "success": true,
  "apartments": [
    {
      "_id": "237e3994874f499a1a5dd555",
      "buildingId": "87d63a2874f499a1a5dd7234",
      "name": "Apartment 101",
      "deviceId": "device_101",
      "deviceName": "Smart Meter 101",
      "__v": 0
    }
  ]
}

Update Apartment

PUT/api/apartments?buildingId=BUILDING_ID

Request Body

{
  "_id": "687e39c0874f499a1a5ddttt",
  "name": "Updated Apt A2",
  "deviceId": "sdfsdf234",
  "deviceName": "Updated Meter"
}

Delete Apartment

DELETE/api/apartments?buildingId=BUILDING_ID

Request Body

{
  "id": "687e39c0874f499a1a5d2344"
}

Example Response

{ "success": true }

Energy Usage APIs

Fetch Apartment kWh Data

POST/api/device-metric

Request Body

{
  "deviceId": "hhu22e2147eebf3961sd23",
  "metric": "totalKwh"
}

Example Response

{
  "success": true,
  "data": [
    { "date": "2025-07-06", "value": 0 },
    { "date": "2025-07-07", "value": 0 },
    { "date": "2025-07-08", "value": 0.29 }
  ]
}

Fetch Total Building Consumption (kWh)

GET/api/building-kwh?buildingId=BUILDING_ID

Example Response

{
  "success": true,
  "totalKwh": 0.56
}

Device Control API

Toggle Device Power (ON/OFF)

POST/api/device-toggle

The target device must be online.

Request Body

{
  "deviceId": "ss22e2147eebf3961dd55",
  "action": "on"
}

Example Response

{ "success": true }

Additional Notes

  • All _id values returned in responses should be used for update/delete operations.
  • Ensure the deviceId is registered and online for control APIs to work.
  • Only totalKwh is supported in metric field for energy queries.