Create an egress template with mapping CSV
POST/api/v1/egress-templates
Uploads a CSV column-mapping file and associated metadata to define a new egress template for data export.
When to use: call this when no existing template covers the target tenant and entity type. To replace the CSV or update metadata on a template that already exists, use PUT /api/v1/egress-templates/{templateId} instead.
Preconditions: tenant-id header must be present and non-blank (returns 400 if missing). templateName and entityType are required form fields; entityType must be one of practitioner, facility, group. status on creation is limited to draft or active — inactive is rejected with 400 at create time.
Defaults applied when omitted: outputFormat -> csv, separator -> ,, status -> draft, scheduleEnabled -> false, scheduleFrequency -> daily, scheduleTime -> 02:00, scheduleTimezone -> UTC (the scheduleFrequency/scheduleTime defaults are skipped when scheduleCron is supplied).
Schedule field rules: scheduleFrequency accepts daily, weekly, monthly, or custom. scheduleCron (Quartz cron syntax, not Unix cron) is required when scheduleFrequency=custom and is rejected for any other frequency. scheduleTime (24-hour HH:mm) is required for daily/weekly/monthly. scheduleDayOfWeek (1 = Sunday ... 7 = Saturday) is required, and only allowed, for weekly. scheduleDayOfMonth (1-31) is required, and only allowed, for monthly.
CSV constraints: maximum file size is 5 MB; exceeding this returns 400. Column attribute paths are validated against the entity type's field schema.
Side effects: the CSV is uploaded to GCS before the template record is written. If the data-store write fails after a successful GCS upload, the GCS object is rolled back so no orphaned file is left behind. Not idempotent — each successful call creates a new template.
Returns: the created template, including the server-assigned id, version set to 1, and mappingsCsvUrl pointing at the uploaded CSV in GCS.
Request
Responses
- 201
- 400
- 401
- 403
The newly created egress template, with server-assigned id, version=1, and the mappings CSV's GCS URL
The request is missing required fields, references an unsupported entityType/status, the CSV failed to parse or exceeds 5 MB, or schedule fields violate the frequency's rules; the error message states which field and why
The request is missing a valid bearer token; re-authenticate and retry
The authenticated caller lacks the create-template permission for this tenant