openapi: 3.1.0
info:
  title: EmacronAI Contact administration
  version: '2026-11-07'
  description: Workspace staff-session operations. Client API keys and Store shopper tokens do not authorize these routes. Privacy completion records a documented human source review and never executes a purge.
servers:
  - url: https://api.crm.emacronai.com
security:
  - WorkspaceSession: []
paths:
  /api/lead-import/csv:
    post:
      summary: Preview or confirm blank-field updates to existing Contacts
      description: Requires current import, Contact access, editing and full customer-number visibility. The reviewed file is limited to 1000 data rows. Confirmation rechecks the same mapping, file, source values and field permissions. Lifecycle, identity, owner, origin and communication restrictions never change in fill mode.
      parameters:
        - {in: query, name: operation, required: true, schema: {type: string, enum: [preview-fill, confirm-fill]}}
        - {in: query, name: mapping, required: true, description: "JSON object mapping zero-based column indices to email, phone, name, company, job_title, website, city or country. Email or phone must identify an unambiguous accessible existing Contact.", schema: {type: string}}
        - {in: header, name: X-Contact-Import-Review, description: Required for confirm-fill. Use the token returned by the matching preview., schema: {type: string}}
      requestBody:
        required: true
        content:
          text/csv:
            schema: {type: string}
      responses:
        '200': {description: Preview token and per-row changes, or committed updated/unchanged/rejected outcomes}
        '400': {description: Invalid file, mapping or unsupported destination}
        '403': {description: Current import, edit, record or field authority denied}
        '409': {description: Preview expired or file, identity, record or access changed}
        '503': {description: No successful write is confirmed; read current state before retrying}
  /api/compliance/erasure-requests/{id}/review:
    parameters:
      - {$ref: '#/components/parameters/RequestId'}
    get:
      summary: Preview current source inventory and resume saved review
      description: Follows explicit Contact and CRM links. Email alone never matches verified Store ownership. Returns grouped reference counts, previous review and an expiring actor/workspace token; private source payloads remain omitted.
      responses:
        '200': {description: Review inventory with review_token and previous_review}
        '403': {description: Active administrator and workspace-wide record authority required}
        '404': {description: Request unavailable in this workspace}
        '503': {description: Source inventory unavailable}
    post:
      summary: Persist partial source-review evidence
      requestBody: {$ref: '#/components/requestBodies/Review'}
      responses:
        '200': {description: In-progress review persisted; purge_executed is false}
        '400': {description: Subject evidence, operation ID or source outcome invalid}
        '403': {description: Review authority denied}
        '409': {description: Stale inventory or conflicting completion operation}
        '503': {description: Review write unconfirmed; read saved request before retrying}
  /api/compliance/erasure-requests/{id}/complete:
    parameters:
      - {$ref: '#/components/parameters/RequestId'}
    post:
      summary: Record completed administrator source review
      description: All nine source sections need evidence. Pending work cannot complete. Linked records cannot be claimed removed or unlinked while they remain. Identical retries reuse operation_id. This records a human review; no source purge runs.
      requestBody: {$ref: '#/components/requestBodies/Review'}
      responses:
        '200': {description: completion_recorded true and purge_executed false, including identical receipt readback}
        '400': {description: Incomplete subject/source evidence}
        '403': {description: Review authority denied}
        '409': {description: Source inventory changed, pending work or conflicting operation}
        '503': {description: Review write unconfirmed; read saved request before retrying}
components:
  securitySchemes:
    WorkspaceSession: {type: http, scheme: bearer, description: Current signed-in CRM workspace session; not a client API key or Store shopper session}
  parameters:
    RequestId: {in: path, name: id, required: true, schema: {type: string, format: uuid}}
  requestBodies:
    Review:
      required: true
      content:
        application/json:
          schema:
            type: object
            required: [operation_id, review_token, subject_verification, sources]
            properties:
              operation_id: {type: string, format: uuid, description: Stable identifier reused only for the same review operation}
              review_token: {type: string, description: Current inventory token returned by GET review}
              subject_verification:
                type: object
                required: [method, reference]
                properties:
                  method: {type: string, enum: [authenticated_source, documented_manual_review]}
                  reference: {type: string, minLength: 3, maxLength: 2000}
              sources:
                type: object
                propertyNames:
                  enum: [contact, crm, inbox, campaigns, store_accounts, billing, consent, audit, other_history]
                description: Complete review requires contact, crm, inbox, campaigns, store_accounts, billing, consent, audit and other_history. Partial saves can omit sections.
                additionalProperties:
                  type: object
                  required: [decision, reference]
                  properties:
                    decision: {type: string, enum: [retained, removed_in_source, not_linked, pending]}
                    reference: {type: string, minLength: 3, maxLength: 2000}
