Table of Contents

**@arolariu/website**


@arolariu/website / lib/actions/invoices/updateInvoice / default

Function: default()

default(input): ServerActionOutputType

Defined in: lib/actions/invoices/updateInvoice.ts:104

Server action that performs a full update (POST) on an invoice.

Parameters

input

ServerActionInputType

The invoice ID and complete invoice object

Returns

ServerActionOutputType

A result object containing the updated invoice or error message

Remarks

HTTP Method: POST Endpoint: /rest/v1/invoices/{invoiceId}

Update Semantics:

  • Replaces the entire invoice resource with the provided data
  • All fields from the provided invoice object are written
  • The invoice ID in the URL must match invoice.id

Validation:

  • invoiceId must be a valid GUID
  • invoice object must be provided and non-null
  • invoice.id must match the invoiceId parameter

Error Handling: Returns a result object with success flag instead of throwing, making it easier to handle errors in UI components.

Throws

Never throws directly; all errors returned via result object

Example

// Fetch, modify, and update the entire invoice
const invoice = await fetchInvoice(invoiceId);
const updatedInvoice = {
  ...invoice,
  name: "Updated Invoice Name",
  description: "New description",
  items: [...invoice.items, newItem],
};

const result = await updateInvoice({
  invoiceId: invoice.id,
  invoice: updatedInvoice,
});

if (result.success) {
  console.log("Updated:", result.invoice);
} else {
  console.error("Failed:", result.error);
}

See

  • patchInvoice for partial updates (when only changing a few fields)
  • fetchInvoice for retrieving invoice data before update