# `validate_ics_payload` — Validate & Auto-Repair .ics Payload

> Part of [CalendarICS Edge API](https://calendar-ics.apikeg.com/llms.txt) (`com.apikeg/calendar-ics`)

Audits raw .ics text for RFC 5545 & iTIP defects (LF-only line breaks, >75-octet lines, missing VCALENDAR/VERSION/PRODID/UID/DTSTAMP/DTSTART, DTEND <= DTSTART, missing VTIMEZONE for TZID, METHOD:CANCEL without STATUS:CANCELLED, METHOD:REQUEST without ORGANIZER, unescaped commas/newlines) and optionally returns a deterministically repaired .ics string.

**Why call instead of DIY:** Catches silent Outlook Desktop, Exchange, Google, and Apple Calendar rejection bugs and auto-repairs broken .ics payloads in <5ms for $0.001.

- **REST Endpoint:** `POST https://calendar-ics.apikeg.com/v1/validate-ics-payload`
- **MCP Server:** `https://calendar-ics.apikeg.com/mcp` (tool: `validate_ics_payload`)
- **Pricing:** $0.001 USD per .ics audit (with optional deterministic auto-repair) (x402 instant micropayment)
- **Free Dry-Run:** `POST https://calendar-ics.apikeg.com/v1/validate-ics-payload?dry_run=true`

## Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "ics": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200000,
      "description": "Raw .ics calendar string to audit against RFC 5545 and Google/Outlook/Apple rules."
    },
    "repair": {
      "type": "boolean",
      "default": false,
      "description": "Set true to deterministically auto-repair CRLF endings, 75-octet UTF-8 folding, missing UID/DTSTAMP/VTIMEZONE, and unescaped text delimiters."
    }
  },
  "required": [
    "ics"
  ],
  "additionalProperties": false
}
```

## Examples
### Audit & Repair Broken LLM-Generated .ics
```bash
curl -X POST "https://calendar-ics.apikeg.com/v1/validate-ics-payload" \
  -H "Content-Type: application/json" \
  -d '{"ics":"BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nDTSTART;TZID=America/New_York:20260715T100000\nSUMMARY:Team Sync, Q3\nEND:VEVENT\nEND:VCALENDAR","repair":true}'
```
Expected output: Flags LF_ONLY_LINE_ENDINGS, MISSING_PRODID, MISSING_UID, MISSING_DTSTAMP, MISSING_VTIMEZONE, UNESCAPED_TEXT_DELIMITER and returns a valid repaired .ics.
