#!/usr/bin/env python3
"""Probe REST /api/scheduler/appointments using cached GAUTAM token."""
import json, sys
from urllib.request import Request, urlopen
from urllib.error import HTTPError
from pathlib import Path

TOKEN = Path("/Users/exult/claude-workspace/config/credentials/amd_session_token.txt").read_text().strip()
print("token len:", len(TOKEN), file=sys.stderr)

base = "https://pm-api-137.advancedmd.com/api"
url = f"{base}/scheduler/columns"
req = Request(url, method="GET", headers={
    "Authorization": f"Bearer {TOKEN}",
    "Accept": "application/vnd.advancedmd.api.v2+json,application/json",
    "Referer": "https://static-100.advancedmd.com/",
})
try:
    with urlopen(req, timeout=30) as resp:
        body = resp.read().decode("utf-8")
        print("STATUS:", resp.status, "len:", len(body), file=sys.stderr)
        print(body[:6000])
except HTTPError as e:
    print("HTTP", e.code, file=sys.stderr)
    print(e.read().decode("utf-8")[:4000])
