Updates a write-off. Only the fields you pass are changed, the rest stay as they were. See [Common Rules](https://developers.controlata.com/hc/api-docs/articles/api-rules) for partial editing.

```
v1/writeoffs/edit.php
```

## Parameters

| Field | Type | Required | Description |
|---|---|---|---|
| writeoff_id | int | Yes | Write-off ID |
| materials | array | No | Materials to write off: id or sku and amount |
| products | array | No | Products to write off: id or sku and amount |
| num | string | No | Number |
| date | string | No | Write-off date, YYYY-MM-DD |
| materials_storage_id | int | No | Storage location materials are written off from. 0: the default write-off storage location |
| products_storage_id | int | No | Storage location products are written off from. 0: the default write-off storage location |
| notes | string | No | Notes |

If at least one of the materials and products arrays is passed, the lines are replaced as a whole, and the array that is not passed is treated as empty. If neither is passed, the lines are unchanged. The status is not changed by this method; use [v1/writeoffs/update_status](https://developers.controlata.com/hc/api-docs/articles/api-writeoffs-update-status).

## Example request

```
{
    "writeoff_id": 19291,
    "materials": [
        {
            "id": 2051,
            "amount": 0.2
        }
    ]
}
```

In this example only materials is passed, so the product is removed from the write-off.

## Example response

```
{
    "success": true
}
```

## Errors

| Error | Reason |
|---|---|
| No writeoff_id in input | writeoff_id is missing |
| Write-off not found or access denied | Write-off not found or deleted |
| No products or materials in input | The line arrays were passed but empty |
| Material with id 2051 not found | Material not found or deleted |
| Amount must be greater than 0 for material with id 2051 | Quantity is not a number or not above 0 after rounding |
| Storage ID not found | Storage location not found or deleted |
| Date is not a valid date in format YYYY-MM-DD | Invalid date format |

Other line errors are the same as in [v1/writeoffs/add](https://developers.controlata.com/hc/api-docs/articles/api-writeoffs-add).
