# NeST Public Tenders · operator notes (rsflow.dspera)

Source: https://nest.go.tz/gateway/nest-data-portal-api

## Endpoints (publicly reachable, no auth)

| Method | Path | Notes |
|---|---|---|
| POST | `/records/tenders` | Body: `{"page":N,"pageSize":N}` · **pageSize hard-capped at 10** by the API |
| GET  | `/api/releases` | Query: `?since=YYYY-MM-DDTHH:MM:SS&cursor=N` · cursor pagination via `links.next` |
| GET  | `/api/records/{ocid}` | Single OCID compiled record |

Every other path under the gateway requires `Authorization: Bearer …`.

## Workflow

**Initial backfill** (one-off, ~5-15 min):
```
php app/cli/nest_backfill.php --since=2025-07-01T00:00:00 --max-pages=2000
```

**Incremental** (Windows Task Scheduler — every 30-60 min):
```
php app/cli/nest_incremental.php
```
No args → `since` = latest `release_date` already in DB. If empty, defaults to `2025-06-01T00:00:00`.

## Windows Task Scheduler

For each task:
- **Program**: `C:\wamp64\bin\php\php8.2.0\php.exe`
- **Arguments**: the script path above (e.g. `app/cli/nest_incremental.php`)
- **Start in**: `C:\wamp64\www\rsflow.dspera\`
- **Trigger**: run every 30-60 minutes; run whether user is logged in or not

## Tables

- `crm_nest_tenders` — one row per OCID. Raw OCDS JSON kept in `raw_release` + `raw_parties`.
- `crm_nest_sync_log` — every CLI run logs start/finish/counts here. Visible via `/NestSync` (admin).
- `crm_nest_watchlist` — per-user starred tenders (populated by users via `/NestTenders`).
- `crm_nest_user_prefs` — per-user category/region/keyword preferences + digest opt-in.

## OCID parsing (financial-year filter)

The OCID encodes FY + category, e.g. `ocds-mv5oob-100607-1-2025-2026-G-01-S001`.
Regex: `/-(\d{4})-(\d{4})-(NC|[GWS])(-\d+)?(-S\d+)?/i`
- Group 1 = FY start year
- Group 2 = FY end year
- Group 3 = category acronym (G = Goods, W = Works, S = Services, NC = Non-Consulting)

Set the constant `NEST_FY_FILTER` in `config/config.php` to a regex if you want to only sync tenders from a specific FY. Leave undefined to accept all matched releases.
