# Buildings API

Manage buildings/properties within the Exit WeWeb Portal system.

# Endpoints

# List Buildings

GET /buildings

Returns buildings based on your role:

  • Super Admin: All buildings
  • Client Admin: All buildings for your client
  • Client Manager: Only assigned buildings

Query Parameters:

  • select - Columns to return
  • client_id - Filter by client (eq)
  • name - Filter by building name (ilike)
  • city - Filter by city (eq, ilike)
  • state - Filter by state (eq)
  • order - Sort results
  • limit - Limit results
  • offset - Pagination offset

Example Request:

GET /buildings?select=id,name,city,state,client_id&client_id=eq.123&city=ilike.*York*
Authorization: Bearer YOUR_TOKEN
apikey: YOUR_ANON_KEY

Response:

[
  {
    "id": 1,
    "name": "Empire State Building",
    "city": "New York",
    "state": "NY",
    "client_id": 123
  }
]

# Get Single Building

GET /buildings?id=eq.BUILDING_ID

Response:

[
  {
    "id": 1,
    "name": "Empire State Building",
    "address": "350 5th Ave",
    "city": "New York",
    "state": "NY",
    "zip": "10118",
    "client_id": 123,
    "created_at": "2025-01-22T10:00:00Z",
    "updated_at": "2025-01-22T10:00:00Z",
    "latitude": 40.748817,
    "longitude": -73.985428,
    "building_type": "commercial",
    "floors": 102,
    "units": 1000
  }
]

# Create Building

POST /buildings
Content-Type: application/json
Prefer: return=representation

Request Body:

{
  "name": "New Building",
  "address": "123 Main St",
  "city": "New York",
  "state": "NY",
  "zip": "10001",
  "client_id": 123,
  "building_type": "residential",
  "floors": 10,
  "units": 50
}

Permissions:

  • Super Admins can create buildings for any client
  • Client Admins can create buildings for their client

# Update Building

PATCH /buildings?id=eq.BUILDING_ID
Content-Type: application/json
Prefer: return=representation

Request Body:

{
  "name": "Updated Building Name",
  "floors": 12,
  "units": 60
}

Permissions:

  • Super Admins can update any building
  • Client Admins can update buildings in their client

# Delete Building

DELETE /buildings?id=eq.BUILDING_ID

Permissions:

  • Super Admins can delete any building
  • Client Admins can delete buildings in their client

# Building Object

interface Building {
  id: number;
  name: string;
  address?: string;
  city?: string;
  state?: string;
  zip?: string;
  client_id: number;
  created_at: string;
  updated_at: string;
  latitude?: number;
  longitude?: number;
  building_type?: string;
  floors?: number;
  units?: number;
}

# Related Endpoints

# Get Building Inspections

GET /inspections?building_id=eq.BUILDING_ID

# Get Building Summary Statistics

GET /rpc/get_building_stats
Content-Type: application/json

{
  "building_id": 123
}

# Assign Buildings to Client Admin

POST /rpc/assign_buildings_to_client_admin
Content-Type: application/json

{
  "admin_id": "uuid",
  "building_ids": [1, 2, 3]
}

# Assign Buildings to Client Manager

POST /rpc/assign_to_client_manager
Content-Type: application/json

{
  "manager_id": "uuid",
  "building_ids": [1, 2, 3],
  "inspection_ids": []
}

# Access Control

Buildings access is controlled through:

  • client_admin_building_access table
  • client_manager_building_access table

Client Admins automatically have access to all buildings in their client. Client Managers only have access to explicitly assigned buildings.