API Documentation

Properties API

Manage property records, settings, and configurations. The Properties API allows you to create, update, retrieve, and delete property information.

Properties

  • GET /v1/properties: List all properties with pagination.
    Query Parameters
    ?page=1&limit=20  // Optional pagination parameters
    Response Format
    {
      "data": [
        {
          "id": "string",
          "name": "string",
          "streetNumber": "string",
          "street": "string",
          "city": "string",
          "state": "string",
          "zip": "string",
          "country": "string",
          "isActive": true,
          "createdAt": "ISO date",
          "updatedAt": "ISO date"
        }
      ],
      "pagination": {
        "total": 10,
        "page": 1,
        "limit": 20,
        "totalPages": 1
      }
    }
  • POST /v1/properties: Create a new property.
    Request Body
    {
      "name": "string (required, max 255 chars)",
      "streetNumber": "string (required, max 50 chars)",
      "street": "string (required, max 255 chars)",
      "city": "string (required, max 100 chars)",
      "state": "string (required, max 50 chars)",
      "zip": "string (required)",
      "country": "string (required, 2-letter ISO code, e.g. 'US')"
    }
  • GET /v1/properties/:id: Get a single property by ID.
  • PATCH /v1/properties/:id: Update a property.
    Request Body
    // All fields are optional for updates
    {
      "name": "string (max 255 chars)",
      "streetNumber": "string (max 50 chars)",
      "street": "string (max 255 chars)",
      "city": "string (max 100 chars)",
      "state": "string (max 50 chars)",
      "zip": "string",
      "country": "string (2-letter ISO code)"
    }
  • DELETE /v1/properties/:id: Delete a property and all related data.
    ⚠️ This permanently deletes the property and all associated units, tenants, bills, and invoices.

Note: For Share Rules management (utility cost allocation), see the dedicated Share Rules section below.

Code Examples

Property Management Examples

Basic property CRUD operations with pagination and error handling. For share rules management, see the dedicated Share Rules examples below.

import requests
import os
import json

# --- Configuration ---
BASE_URL = "https://app.billgauge.com/api/v1"
# Store your API key in an environment variable for security
API_KEY = os.environ.get("BILLGAUGE_API_KEY", "your_api_key_here")

HEADERS = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
}

def handle_response(response, operation="API call"):
    """Helper function to handle API responses with error checking."""
    print(f"--- {operation} ---")
    print(f"Status Code: {response.status_code}")
    
    if response.ok:
        data = response.json()
        print("✅ Success!")
        print(json.dumps(data, indent=2))
        return data
    else:
        print("❌ Error!")
        try:
            error_data = response.json()
            print(json.dumps(error_data, indent=2))
        except:
            print(response.text)
        return None

def list_properties(page=1, limit=20):
    """List all properties with pagination."""
    params = {"page": page, "limit": limit}
    response = requests.get(f"{BASE_URL}/properties", headers=HEADERS, params=params)
    return handle_response(response, f"List Properties (Page {page})")

def create_property(name, street_number, street, city, state, zip_code, country="US"):
    """Create a new property."""
    property_data = {
        "name": name,
        "streetNumber": street_number,
        "street": street,
        "city": city,
        "state": state,
        "zip": zip_code,
        "country": country
    }
    response = requests.post(f"{BASE_URL}/properties", headers=HEADERS, json=property_data)
    return handle_response(response, "Create Property")

def get_property(property_id):
    """Get a single property by ID."""
    response = requests.get(f"{BASE_URL}/properties/{property_id}", headers=HEADERS)
    return handle_response(response, f"Get Property {property_id}")

def update_property(property_id, **updates):
    """Update a property with the provided fields."""
    response = requests.patch(f"{BASE_URL}/properties/{property_id}", headers=HEADERS, json=updates)
    return handle_response(response, f"Update Property {property_id}")

def delete_property(property_id):
    """Delete a property (WARNING: This deletes all related data!)."""
    response = requests.delete(f"{BASE_URL}/properties/{property_id}", headers=HEADERS)
    return handle_response(response, f"Delete Property {property_id}")

def get_property_share_rules(property_id):
    """Get all share rules for a property. For more advanced share rules management, see Share Rules examples."""
    response = requests.get(f"{BASE_URL}/properties/{property_id}/sharerules", headers=HEADERS)
    return handle_response(response, f"Get Share Rules for Property {property_id}")

# --- Example Usage ---
if __name__ == "__main__":
    if API_KEY == "your_api_key_here":
        print("!!! PLEASE UPDATE THE API_KEY in the script before running. !!!")
    else:
        print("🏢 Property Management API Examples\n")
        
        # 1. List existing properties
        properties_data = list_properties(page=1, limit=5)
        
        # 2. Create a new property
        new_property = create_property(
            name="Sunset Apartments",
            street_number="123",
            street="Main Street",
            city="San Francisco",
            state="CA",
            zip_code="94102"
        )
        
        if new_property and new_property.get("id"):
            property_id = new_property["id"]
            
            # 3. Get the created property
            get_property(property_id)
            
            # 4. Update the property
            update_property(property_id, name="Sunset Luxury Apartments")
            
            # 5. Get default share rules (created automatically)
            get_property_share_rules(property_id)
            
            # Note: For comprehensive share rules management (create, update, delete),
            # see the dedicated Share Rules examples below
            
            # 6. Clean up - delete the test property
            print("\n🧹 Cleaning up test data...")
            delete_property(property_id)
        
        print("\n✨ Example completed!")
        print("\n💡 For advanced share rules management, see the Share Rules section!")