Postman collection
Invoices Write

pixiDeleteInvoicePackage

Deletes a shipping package and its package lines from an invoice and updates the invoice's tracking IDs and package count.

Removes one package record (pixi.InvoicePackage) that belongs to an invoice (Rechnung), for example after a shipping label was cancelled.

The call runs these checks in order and returns a single Response row in every case:

  1. The package PackageId must exist. Otherwise: 400 Bad Request - Package ID does not exist.
  2. The package must belong to the invoice InvoiceKey. Otherwise: 400 Bad Request - Invoice ID does not match the package.
  3. The invoice must have more than one package. The last remaining package of an invoice cannot be deleted: 400 Bad Request - This is the last package for invoice and delete is not allowed.

If all checks pass:

  • all package lines (pixi.InvoicePackageLines) of the package are deleted,
  • the package itself is deleted,
  • in Invoices the package's tracking ID followed by ; is removed from ShipmentTrackingID, and Packages is set to the number of packages that remain for the invoice,
  • 200 OK is returned.

Notes

  • All changes run in a transaction (or a savepoint if the caller already has an open transaction). On any SQL error the changes are rolled back, the error is logged via log.InsertError and 500 Internal Server Error is returned as a normal row, not as a SqlMessage.
  • The existence and count checks read pixi.InvoicePackage with NOLOCK, so concurrent changes may not be seen.
  • The tracking ID is only removed from ShipmentTrackingID when it is followed by ;. A tracking ID at the end of the list without a trailing semicolon stays in the field. REPLACE removes every occurrence of the pattern.
  • If the package has no TrackingID (NULL), the REPLACE expression yields NULL, so ShipmentTrackingID of the invoice is set to NULL.
  • ReturnTrackingId of the package is read but not removed from the invoice.
  • Passing NULL for InvoiceKey always leads to the "does not match" response.

Tables used

InvoicePackage · Write InvoicePackageLines · Write Invoices · Write
SQL object:
dbo.pipiDeleteInvoicePackage
Updated at 2026-10-30