@arolariu/website / lib/actions/invoices/attachInvoiceScan / attachInvoiceScan
Function: attachInvoiceScan()
attachInvoiceScan(
input):ServerActionOutputType
Defined in: lib/actions/invoices/attachInvoiceScan.ts:91
Attaches a new scan to an existing invoice entity.
Parameters
input
ServerActionInputType
The invoice ID and scan payload
Returns
ServerActionOutputType
Promise that resolves when scan is successfully attached
Remarks
Execution Context: Server-side only (Next.js server action).
Authentication: Automatically fetches JWT from Clerk auth service.
Scan Types:
Photo: Camera capture of physical receiptDocument: PDF or scanned documentScreenshot: Digital receipt capture
Side Effects:
- Emits OpenTelemetry spans for tracing
- Updates invoice aggregate with new scan reference
- May trigger re-analysis if configured
Error Handling: Throws on validation, auth, or API failures.
Throws
When invoiceId is not a valid GUID
Throws
When authentication fails
Throws
When API returns non-OK status (e.g., 400, 404)
Example
import {attachInvoiceScan} from "@/lib/actions/invoices/attachInvoiceScan";
import {InvoiceScanType} from "@/types/invoices";
await attachInvoiceScan({
invoiceId: "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
payload: {
type: InvoiceScanType.Photo,
location: "https://storage.blob.core.windows.net/invoices/scan.jpg",
additionalMetadata: { page: "2" }
}
});
See
createInvoiceScan for uploading the scan file first