Table of Contents

**@arolariu/website**


@arolariu/website / lib/actions/invoices/createInvoice / createInvoice

Function: createInvoice()

createInvoice(payload): ServerActionOutputType

Defined in: lib/actions/invoices/createInvoice.ts:88

Creates a new invoice entity in the backend system.

Parameters

payload

ServerActionInputType

Partial invoice creation payload

Returns

ServerActionOutputType

Promise resolving to the created Invoice with generated ID

Remarks

Execution Context: Server-side only (Next.js server action).

Authentication: Automatically fetches JWT and user ID from Clerk. If userIdentifier is not provided in payload, it's automatically populated from the authenticated user.

Side Effects:

  • Creates new invoice aggregate in database
  • Emits OpenTelemetry spans for tracing
  • Associates invoice with authenticated user

Validation:

  • Backend validates all required fields
  • Scan URL must be a valid Azure Blob URL

Throws

When authentication fails

Throws

When API returns non-OK status (e.g., 400 for validation)

Example

import {createInvoice} from "@/lib/actions/invoices/createInvoice";
import {InvoiceScanType} from "@/types/invoices";

const invoice = await createInvoice({
  initialScan: {
    scanType: InvoiceScanType.Photo,
    location: "https://storage.blob.core.windows.net/invoices/scan.jpg",
    metadata: {}
  },
  metadata: {
    isImportant: "false",
    requiresAnalysis: "true"
  }
});

console.log("Created invoice:", invoice.id);

See

Invoice for the returned entity structure