> ## Documentation Index
> Fetch the complete documentation index at: https://kb.manage.management/llms.txt
> Use this file to discover all available pages before exploring further.

# MRI API Reference

> Technical documentation for the MRI integration API

## Overview

The MRI integration uses the MRI MIX REST API with HTTP Basic Auth over HTTPS. This reference documents our internal service layer that wraps the MRI API.

<Note>
  This documentation is for developers building on or extending the integration.
</Note>

## Authentication

### HTTP Basic Auth over HTTPS

```typescript theme={null}
// Every API request uses HTTP Basic Auth
GET https://{your-mri-server}/MIXApi/properties

Authorization: Basic {base64(clientId:password)}
X-MRI-Database: {databaseName}
X-MRI-User: {userName}
X-MRI-PartnerKey: {partnerKey}
```

### Required Credentials

| Credential        | Description                                                              |
| ----------------- | ------------------------------------------------------------------------ |
| **Client ID**     | Your MRI API client identifier                                           |
| **Database Name** | The MRI database to connect to                                           |
| **User Name**     | MRI API user name                                                        |
| **Partner Key**   | MRI partner integration key                                              |
| **Password**      | MRI API password                                                         |
| **Base URL**      | Your MRI server URL (e.g., `https://your-server.mrisoftware.com/MIXApi`) |

<Warning>
  All credentials are encrypted in Supabase Vault. Never store them in plain text or expose them to the frontend.
</Warning>

## Service Configuration

```typescript theme={null}
interface MRIConfig {
  baseUrl: string;           // MRI server MIX API base URL
  clientId: string;          // MRI client ID
  databaseName: string;      // MRI database name
  userName: string;          // MRI user name
  partnerKey: string;        // MRI partner key
  password: string;          // MRI password (encrypted in Vault)
  environment: 'sandbox' | 'production';
}

interface MRIServiceConfig {
  rateLimiting: {
    requestsPerMinute: 60;
    requestsPerHour: 1000;
    burstLimit: 10;
  };
  retry: {
    maxRetries: 3;
    baseDelay: 1000;
    maxDelay: 10000;
    backoffMultiplier: 2;
  };
  timeout: {
    connectionTimeout: 10000;
    requestTimeout: 30000;
  };
}
```

## API Endpoints

### Properties

<ParamField path="propertyId" type="string" required>
  The MRI property identifier
</ParamField>

```typescript theme={null}
// List all properties
GET /api/v1/properties?page={page}&limit={limit}

// Get single property
GET /api/v1/properties/{propertyId}

// Get units for property
GET /api/v1/properties/{propertyId}/units
```

### Tenancies

```typescript theme={null}
// List tenancies for property
GET /api/v1/properties/{propertyId}/tenancies

// Get single tenancy
GET /api/v1/tenancies/{tenancyId}
```

### Contacts

```typescript theme={null}
// List all contacts
GET /api/v1/contacts?type={contactType}

// Get single contact
GET /api/v1/contacts/{contactId}
```

**Contact Types:** `tenant`, `owner`, `director`, `agent`, `supplier`

### Financial

```typescript theme={null}
// List transactions
GET /api/v1/properties/{propertyId}/transactions
    ?start_date={date}&end_date={date}&page={page}&limit={limit}

// List budgets
GET /api/v1/properties/{propertyId}/budgets?year={year}

// List invoices
GET /api/v1/properties/{propertyId}/invoices?status={status}
```

### Maintenance

```typescript theme={null}
// List work orders
GET /api/v1/properties/{propertyId}/work-orders?status={status}

// Get single work order
GET /api/v1/work-orders/{workOrderId}
```

### Documents

```typescript theme={null}
// List documents
GET /api/v1/properties/{propertyId}/documents?category={category}

// Get document metadata
GET /api/v1/documents/{documentId}

// Download document
GET /api/v1/documents/{documentId}/download
```

## Response Format

All API responses follow this structure:

```typescript theme={null}
interface MRIApiResponse<T> {
  success: boolean;
  data?: T;
  error?: string;
  pagination?: {
    page: number;
    limit: number;
    total: number;
    hasMore: boolean;
  };
}
```

## Rate Limiting

The integration implements automatic rate limiting:

* **60 requests/minute** sustained rate
* **1000 requests/hour** hourly limit
* **10 request burst** for short spikes

When rate limited, requests queue and retry with exponential backoff.

## Error Codes

| Code | Meaning      | Action                           |
| ---- | ------------ | -------------------------------- |
| 401  | Unauthorized | Token expired, will auto-refresh |
| 403  | Forbidden    | Check API permissions            |
| 404  | Not Found    | Resource doesn't exist in MRI    |
| 429  | Rate Limited | Wait and retry (automatic)       |
| 500  | Server Error | Retry with backoff               |
