Skip to main content

Reclassify Document Type

POST 

/api/document-inbox/customer_po/:extraction_id/reclassify

Reclassify an inbox extraction as a different document type — the user-facing escape hatch when automatic type detection got it wrong. Copies the original file into the target pipeline, creates a new extraction there, and rejects the source extraction with a back-reference.

Path params:

  • type (required) — current document type: one of customer_po, supplier_invoice, vendor_credit, or landed_cost_invoice (regex-constrained at the route level; unknown values return 404)
  • id (required, integer) — extraction ID

Request body:

  • target_type (required, string, in:customer_po,supplier_invoice,vendor_credit,landed_cost_invoice) — the type to reclassify the document as (returns 422 validation error otherwise)

Behavior:

  • Source extraction must be in a reclassifiable status: pending_review, duplicate_detected, or failed
  • Three pairwise conversions are delegated to their existing dedicated flows (which can reuse the stored Azure raw_response to avoid a second OCR charge): customer_po → supplier_invoice, supplier_invoice → vendor_credit, and vendor_credit → supplier_invoice
  • All other source/target pairs use the generic flow: the original file is copied from the source pipeline's storage into the target pipeline's staging directory, a new extraction row is created in the target table, and the target's OCR job is dispatched. When the source already has a stored raw_response and the target is supplier_invoice or vendor_credit, the result is parsed synchronously instead of dispatching a job
  • The source extraction is marked rejected with error_message "Reclassified as {label} (extraction #{id})." inside the same transaction

Response 200:

{
"message": "Document reclassified.",
"data": { "type": "supplier_invoice", "id": 88 }
}

data.type/data.id identify the NEW extraction so the frontend can route straight to the correct OCR review page.

Errors (422, { "error": "..." }):

  • "The document is already classified as a {label}." — target_type equals the current type
  • "Only extractions pending review can be reclassified." — source status not in pending_review/duplicate_detected/failed
  • "Original OCR file is no longer available." — source file_path is empty
  • Standard Laravel validation error when target_type is missing or not one of the four allowed values

Response 404: route constraint blocks unknown type path values; unknown id returns 404 via findOrFail.

Request

Responses

Successful response