# Update a debit memo

Operation ID: `updateDebitMemo`

Group: Accounting › Debit Memos

[Open in the interactive reference](https://lensing.ai/api-docs/lensing/v1/endpoints/updateDebitMemo)

`PATCH /accounting/debit-memos/{id}`

Retry-safe: A write that accepts Idempotency-Key: repeating a request with the same key replays the stored answer instead of executing twice.

Updates a debit memo with the fields you send. A field you leave out keeps its current value.

Use the debit memo's id, not its debitMemoNumber.

What you can change follows the approval status, as on the debit memo page. While a debit memo isn't approved yet (draft, pendingApproval or revise), you can change its dates, payment term, debit account, addresses and text, and add, change or remove lines with createLines, updateLines and deleteLines. Editing a debit memo that is pending approval puts it back in revise. Once it's approved, you can still change customerMessage, purchaseOrder, paymentTerm, dueDate and the addresses, debitMemoDate while no payment or credit is applied, and a line's description; anything else fails with FIELD_LOCKED, LINES_LOCKED or DATE_LOCKED.

When you change paymentTerm or debitMemoDate and leave out dueDate, the due date is recomputed from the date and the term's days. Line edits don't recalculate tax.

The response is empty. Read the updated record with GET accounting/debit-memos/:id.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Api-Version` | header | string · v1 | yes | The API version this request targets, named by its public identifier. Required on every request; omitting it, or naming a version this company does not have, is answered with 400. This document describes version `v1`. |
| `Idempotency-Key` | header | string | no | An opaque caller-chosen string (1-255 characters) that makes this request safe to retry. Repeating the same key with an identical request body replays the original response instead of re-executing - but only once that original request succeeded; a failed attempt re-executes on retry. Repeating the key with a different body is answered with 422. A key still in flight is answered with 409 - as is a key whose original request was interrupted before it finished, for a few minutes afterwards, until that attempt is presumed dead. A completed response stays replayable for 24 hours. The key is scoped to the caller, not to the action: reusing it for a different action is answered with 409 or 422 rather than treated independently. On read actions this header is ignored. On write actions that cannot offer the guarantee it is answered with `400 IDEMPOTENCY_NOT_SUPPORTED` rather than silently ignored. |
| `id` | path | string | yes | The unique identifier of the debit memo you want to update. |

## Request body

Required, `application/json`: updateDebitMemoInput.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `customerMessage` | string | no | A new free-text message to show the customer on the document. Pass an empty string to clear it. Example: `"Revised: covers the re-debited licence fee only."`. |
| `purchaseOrder` | string | no | A new purchase-order reference from the customer. Pass an empty string to clear it. Example: `"PO-88214"`. |
| `paymentTerm` | string | no | A new payment-term key to record on the document. When you leave out dueDate, the due date is recomputed from debitMemoDate plus this term's days. An unknown key fails with PAYMENT_TERM_NOT_FOUND. See code on GET accounting/payment-terms. |
| `debitMemoDate` | date | no | A new date for the debit memo. Use format YYYY-MM-DD. It must fall in an open accounting period, or the request fails with ACCOUNTING_PERIOD_CLOSED. On an approved debit memo it can move only while no payment or credit is applied, or the request fails with DATE_LOCKED. When you leave out dueDate and the debit memo has a payment term, the due date moves with it. |
| `dueDate` | date | no | A new due date. Use format YYYY-MM-DD. Must not be before the debit memo date, or the request fails with DUE_DATE_BEFORE_DEBIT_MEMO_DATE. |
| `debitGlAccountId` | string | no | A new general ledger account for the journal entry's debit. Only on a debit memo that isn't approved yet; on an approved one the request fails with FIELD_LOCKED. See id on GET accounting/accounts/:id. |
| `billToAddressId` | string | no | A new bill-to address for the document. There is no endpoint for it. |
| `soldToAddressId` | string | no | A new sold-to address for the document. There is no endpoint for it. |
| `createLines` | array<object> | no | Lines to add, on a standalone debit memo that isn't approved yet. They follow the same rules as the lines of a new debit memo. Identifiers for them are set afterwards through lineExternalIdentifiers. |
| `createLines[].description` | string | no | A free-text line description, shown to the customer. Required on a line that names no product. |
| `createLines[].productId` | string | no | The product the line refers to. See id on GET accounting/products/:id. |
| `createLines[].productLineId` | string | no | The product line the line bills. Its product, unit of measure and tax mode apply when you leave those out. Must be a line of productId when you send both, or the request fails with PRODUCT_LINE_NOT_FOUND. |
| `createLines[].quantity` | decimal | no | The quantity debited. A count, not an amount, so it has no currency. Required on a line that names a product. |
| `createLines[].unitOfMeasure` | string | no | The unit-of-measure key, for example 'each'. An unrecognized value fails with INVALID_ENUM_VALUE. |
| `createLines[].unitPrice` | decimal | no | The price per unit, in the debit memo currency. Required on a line that names a product. |
| `createLines[].adjustedUnitPrice` | decimal | no | The price per unit after adjustment, in the debit memo currency. |
| `createLines[].totalPrice` | decimal | yes | The line total excluding tax, in the debit memo currency. Must be greater than 0. |
| `createLines[].taxAmount` | decimal | no | The tax on the line, in the debit memo currency. A line edit does not recalculate tax; send the new amount, or recalculate it on the debit memo page. |
| `createLines[].taxCode` | string | no | The tax code to apply to the line. |
| `createLines[].taxDate` | date | no | The date to determine the line's tax on. Use format YYYY-MM-DD. |
| `createLines[].taxMode` | string | no | How the line's prices are quoted for tax. One of: `"taxInclusive"`, `"taxExclusive"`. |
| `createLines[].taxExemptCode` | string | no | The customer-level tax-exempt code to apply to the line. |
| `createLines[].creditGlAccountId` | string | no | The line's credit general ledger account, the credit side of the journal entry. Required on a line that names no product. See id on GET accounting/accounts/:id. |
| `createLines[].vatAccountingType` | string | no | The VAT type of the line. Required on every line when the legal entity has VAT enabled and no tax engine. One of: `"domesticStandardRate"`, `"domesticReducedRate"`, `"domesticSalesZeroRated"`, `"domesticSalesExempt"`, `"vatIntraEuStandardRate"`, `"vatIntraEuReducedRate"`, `"nonEuExempt"`, `"reverseCharge"`. |
| `createLines[].serviceStartDate` | date | no | The first day of the service period the line covers. Use format YYYY-MM-DD. |
| `createLines[].serviceEndDate` | date | no | The last day of the service period the line covers, inclusive. Use format YYYY-MM-DD. |
| `updateLines` | array<object> | no | Lines to change, each matched by its id. A field you leave out keeps its current value. On an approved debit memo only description can change; any other field fails with FIELD_LOCKED. |
| `updateLines[].id` | string | yes | The line to change. Must be a line of this debit memo, or the request fails with LINE_NOT_FOUND. See lines[].id on GET accounting/debit-memos/:id. |
| `updateLines[].description` | string | no | A free-text line description, shown to the customer. Omit to leave it unchanged. Required on a line that names no product. |
| `updateLines[].productId` | string | no | The product the line refers to. Sending it or productLineId replaces the line's product. See id on GET accounting/products/:id. |
| `updateLines[].productLineId` | string | no | The product line the line bills. Its product, unit of measure and tax mode apply when you leave those out. Must be a line of productId when you send both, or the request fails with PRODUCT_LINE_NOT_FOUND. |
| `updateLines[].quantity` | decimal | no | The quantity debited. A count, not an amount, so it has no currency. Omit to leave it unchanged. Required on a line that names a product. |
| `updateLines[].unitOfMeasure` | string | no | The unit-of-measure key, for example 'each'. An unrecognized value fails with INVALID_ENUM_VALUE. |
| `updateLines[].unitPrice` | decimal | no | The price per unit, in the debit memo currency. Omit to leave it unchanged. Required on a line that names a product. |
| `updateLines[].adjustedUnitPrice` | decimal | no | The price per unit after adjustment, in the debit memo currency. |
| `updateLines[].totalPrice` | decimal | no | The line total excluding tax, in the debit memo currency. Must be greater than 0. Omit to leave it unchanged. |
| `updateLines[].taxAmount` | decimal | no | The tax on the line, in the debit memo currency. A line edit does not recalculate tax; send the new amount, or recalculate it on the debit memo page. |
| `updateLines[].taxCode` | string | no | The tax code to apply to the line. |
| `updateLines[].taxDate` | date | no | The date to determine the line's tax on. Use format YYYY-MM-DD. |
| `updateLines[].taxMode` | string | no | How the line's prices are quoted for tax. One of: `"taxInclusive"`, `"taxExclusive"`. |
| `updateLines[].taxExemptCode` | string | no | The customer-level tax-exempt code to apply to the line. |
| `updateLines[].creditGlAccountId` | string | no | The line's credit general ledger account, the credit side of the journal entry. Omit to leave it unchanged. Required on a line that names no product. See id on GET accounting/accounts/:id. |
| `updateLines[].vatAccountingType` | string | no | The VAT type of the line. Required on every line when the legal entity has VAT enabled and no tax engine. One of: `"domesticStandardRate"`, `"domesticReducedRate"`, `"domesticSalesZeroRated"`, `"domesticSalesExempt"`, `"vatIntraEuStandardRate"`, `"vatIntraEuReducedRate"`, `"nonEuExempt"`, `"reverseCharge"`. |
| `updateLines[].serviceStartDate` | date | no | The first day of the service period the line covers. Use format YYYY-MM-DD. |
| `updateLines[].serviceEndDate` | date | no | The last day of the service period the line covers, inclusive. Use format YYYY-MM-DD. |
| `deleteLines` | array<string> | no | The ids of lines to remove, on a debit memo that isn't approved yet. At least one line has to remain, or the request fails with NO_LINES. See lines[].id on GET accounting/debit-memos/:id. |
| `externalIdentifiers` | array<object> | no | The debit memo's identifiers in other systems, one per configured field name. Identifiers already stored under other field names are kept. Each fieldName must be the fieldName of an existing debit-memo external-identifier configuration, or the request fails with UNKNOWN_EXTERNAL_IDENTIFIER. |
| `externalIdentifiers[].fieldName` | string | yes | The configured field name of the identifier, for example 'Maxio Invoice Key'. |
| `externalIdentifiers[].value` | string | yes | The identifier in the other system. |
| `externalIdentifiers[].externalUrl` | string | no | A link to the record in the other system. |
| `lineExternalIdentifiers` | array<object> | no | External identifiers to set on lines of this debit memo, one entry per line. Each line keeps the identifiers it does not name. |
| `lineExternalIdentifiers[].lineId` | string | yes | The line to set them on. Must be a line of this debit memo, or the request fails with LINE_NOT_FOUND. See lines[].id on GET accounting/debit-memos/:id. |
| `lineExternalIdentifiers[].externalIdentifiers` | array<object> | yes | The line's identifiers in other systems, one per configured field name. Each fieldName must be the fieldName of an existing debit-memo-line external-identifier configuration, or the request fails with UNKNOWN_EXTERNAL_IDENTIFIER. |
| `lineExternalIdentifiers[].externalIdentifiers[].fieldName` | string | yes | The configured field name of the identifier, for example 'Maxio Invoice Key'. |
| `lineExternalIdentifiers[].externalIdentifiers[].value` | string | yes | The identifier in the other system. |
| `lineExternalIdentifiers[].externalIdentifiers[].externalUrl` | string | no | A link to the record in the other system. |

```json
{}
```

## Response

`200` Success

```json
{
  "data": {},
  "diagnostics": [
    {
      "code": "<code>",
      "message": "<message>",
      "severity": "error",
      "path": [
        "<path>"
      ],
      "details": "<details>"
    }
  ]
}
```

## Response headers

- `Idempotency-Replayed` — Present and `true` only when this response replays a previously stored one for the same Idempotency-Key, rather than reflecting a live execution. Absent on a live response - never sent as `false`.

## Errors

| Code | Status |
| --- | --- |
| `NOT_FOUND` | 400 |
| `UNKNOWN_EXTERNAL_IDENTIFIER` | 400 |
| `LINE_NOT_FOUND` | 400 |
| `PAYMENT_TERM_NOT_FOUND` | 400 |
| `PRODUCT_NOT_FOUND` | 400 |
| `PRODUCT_LINE_NOT_FOUND` | 400 |
| `ACCOUNT_NOT_FOUND` | 400 |
| `ADDRESS_NOT_FOUND` | 400 |
| `FIELD_NOT_ALLOWED` | 400 |
| `FIELD_LOCKED` | 400 |
| `LINES_LOCKED` | 400 |
| `DATE_LOCKED` | 400 |
| `ACCOUNTING_PERIOD_NOT_FOUND` | 400 |
| `ACCOUNTING_PERIOD_CLOSED` | 400 |
| `DUE_DATE_BEFORE_DEBIT_MEMO_DATE` | 400 |
| `INVALID_AMOUNT` | 400 |
| `INVALID_ENUM_VALUE` | 400 |
| `NO_LINES` | 400 |
| `MISSING_REQUIRED_FIELD` | 400 |
| `IDEMPOTENCY_KEY_CONFLICT` | 409 |
| `IDEMPOTENCY_PAYLOAD_MISMATCH` | 422 |

## Statuses

- `400` — Invalid request or business failure. Codes: NOT_FOUND, UNKNOWN_EXTERNAL_IDENTIFIER, LINE_NOT_FOUND, PAYMENT_TERM_NOT_FOUND, PRODUCT_NOT_FOUND, PRODUCT_LINE_NOT_FOUND, ACCOUNT_NOT_FOUND, ADDRESS_NOT_FOUND, FIELD_NOT_ALLOWED, FIELD_LOCKED, LINES_LOCKED, DATE_LOCKED, ACCOUNTING_PERIOD_NOT_FOUND, ACCOUNTING_PERIOD_CLOSED, DUE_DATE_BEFORE_DEBIT_MEMO_DATE, INVALID_AMOUNT, INVALID_ENUM_VALUE, NO_LINES, MISSING_REQUIRED_FIELD
- `401` — The request carries no valid access token.
- `403` — Not authorized
- `404` — Not found
- `409` — The Idempotency-Key is still being processed by another request.
- `422` — The Idempotency-Key was already used with a different request payload.
- `429` — Too many requests from this client address. The response has no body and no `Retry-After` header.
- `500` — Internal server error
