# Morning Rounds — Atlas API Contract for Riv

**Date:** 2026-05-22
**Status:** Phase 1 shell LIVE at http://localhost:3001/rounds (3001 = test; 3000 = prod after PM2 reload)

## New Endpoints

### POST /api/rounds/sync-queue
Called by Riv to sync QBO write queue items from Google Sheets into Atlas.

Auth: ATLAS_INGEST_TOKEN in body

Request body:
{
  "token": "<ATLAS_INGEST_TOKEN>",
  "items": [
    {
      "client_name": "Afton Electric",
      "description": "Void dup payment - Mike Fischer",
      "amount": 850.00,
      "action_type": "void_payment",
      "queued_by": "ledger",
      "sheet_row_id": "R77",
      "payload": { "txn_id": 17650 }
    }
  ]
}

action_type values: void_payment, void_invoice, null_fix, create_bill, create_payment, journal_entry

### POST /api/rounds/run-worker
Called by the Run Worker button in the UI (or by Riv automation).
Marks all approved items with a run_id. Returns: { run_id, items }
Riv needs to wire: poll for items WHERE worker_run_id IS NOT NULL -> run QBO worker -> mark done.

### POST /api/rounds/activity
Agents log completed work here.
Auth: Bearer <ATLAS_INGEST_TOKEN>

Request body:
{ "client_name": string, "summary": string, "agent": string, "status"?: "done"|"in_progress"|"blocked", "log_date"?: "YYYY-MM-DD" }

### POST /api/rounds/flag
Agents raise anomaly flags here.
Auth: Bearer <ATLAS_INGEST_TOKEN>

Request body:
{ "client_name": string, "flag": string, "flagged_by": string, "severity"?: "low"|"medium"|"high" }

### PATCH /api/rounds/flag
Resolve a flag (Jimmie clicks Resolve in the UI).
Body: { "id": number, "notes"?: string }

### PATCH /api/rounds/approve
Toggle Y/N on a queue item (Jimmie clicks in the UI).
Body: { "id": number, "approved": boolean }

## Tables Created

- rounds_approval_queue — pending QBO actions
- rounds_activity_log — per-agent/per-client work log
- rounds_anomaly_flags — unresolved judgment calls

## Riv Build Tasks (Phase 2)

1. Google Sheets write queue -> POST /api/rounds/sync-queue (on each sheet update)
2. Poll for worker_run_id IS NOT NULL -> trigger QBO worker.py -> mark worker_run_id as complete
3. Slack morning ping with link to http://atlas.local/rounds
4. Wire Ledger/Tally/Larry to POST /api/rounds/activity when they complete tasks
5. Wire Ledger/Tally to POST /api/rounds/flag when they detect anomalies

## PM2 Reload Needed
Build is complete. Run in elevated PowerShell:
  pm2 reload C:PKAAtlasappecosystem.config.js