# Local API Endpoints

These endpoints read from the synchronized `api_payments` and `api_claims` tables.

## 1. Payments

**Method:** `GET`  
**Path:** `api/get-payments.php`

**Body (raw JSON):**

```json
{
  "paid_date_from": "2026-06-18 00:00:00",
  "paid_date_to": "2026-06-18 23:59:59"
}
```

**Response:**

```json
{
  "ok": true,
  "data": [
    {
      "Policynum": "POLICY001234",
      "fullname": "SAMPLE CUSTOMER",
      "policy_product": "Funeral",
      "commence_date": "2021-10-31 00:00:00",
      "amountreceived": "66.580",
      "paymentmethod": "MOBILE MONEY",
      "deduction_date": "2025-12-31",
      "paiddate": "2026-01-20 00:00:00",
      "agent_code": "AG001",
      "agent_name": "Sample Agent",
      "branch": "Accra"
    }
  ]
}
```

## 2. Claims

**Method:** `GET`  
**Path:** `api/get-claims.php`

**Body (raw JSON):**

```json
{
  "claims_paid_date_from": "2026-01-01 00:00:00",
  "claims_paid_date_to": "2026-01-18 23:59:59"
}
```

**Response:**

```json
{
  "ok": true,
  "data": [
    {
      "claim_id": "CLM000123",
      "policy_number": "POLICY009876",
      "policy_product": null,
      "classification": "Surrender",
      "amount": null,
      "status": null,
      "cheque_date": null
    }
  ]
}
```

## Upstream synchronization

The server-side sync client calls the provider endpoints exactly as documented: a `GET` request with a JSON body and `Authorization: Bearer <token>`.

Configure the provider connection in `sync_settings.php`.

## Sync reliability and dashboard notes (v17)

- The upstream request remains `GET` with a raw JSON body, as documented.
- The PHP cURL client forces HTTP/1.1, lets cURL calculate `Content-Length`, and
  suppresses `Expect: 100-continue` for reverse-proxy compatibility.
- Endpoint Tests use the exact test range entered on `sync_settings.php`.
- Historical/manual synchronization starts with configurable minute-sized batches (default 60 minutes).
- Timeout/oversized batches are recursively split into smaller time slices down to the configured minimum.
- Responses larger than the configured safety ceiling (default 12 MB) are aborted early instead of waiting for a gateway timeout.
- Automatic synchronization resumes near the latest successfully covered Payments/Claims API range with a one-hour overlap; the configured lookback is a first-run ceiling rather than a full re-download on every scheduler pass.
- Bearer tokens are masked in database diagnostics, cURL info, verbose traces and
  file logs.


### v17 dashboard integration
- Full filtered CSV exports are available through `export.php?type=payments` and `export.php?type=claims`.
- The Claims API has no branch field; branch filtering is therefore not applied to Claims.
- Dashboard decision alerts wait for payment analytics completion and the Claims summary check.
