# updateTransferAdvice mutation


`updateTransferAdvice` is a GraphQL mutation of the Chameleoon MAX API. Send it as `POST https://max-api.chameleoon.sk/api/v1/graphql` with your API key, see [Chameleoon MAX](/chameleoon-max).

Updates an `OPEN` transfer advice in one transaction: all of it happens or none of it. Call it
when the work to be done changes.

#### Permissions

Requires the `transferAdvice.write` and `transferAdvice.read` permissions, with both
warehouses in your API key's warehouse scope and the company in its legal-entity scope.

#### Repeated calls

`requestId` makes a retry after a lost response safe. Use a new `requestId` for every change
you intend.

- The same `requestId` with the same input returns `applied: false` and the transfer advice as
  it is now, even if it has closed since. Nothing changes.
- The same `requestId` with other input, or on another transfer advice, returns `CONFLICT` with
  `extensions.reason` `REQUEST_ID_REUSED`.

#### Order of the changes

MAX applies `removeLineIds`, `updateLines` and `addLines`, in that order. Then it applies
`plannedAt` and `reference`, and then `parameters`.

#### Rules

- A line that has moved goods keeps its product, bins and lot
  (`TRANSFER_ADVICE_LINE_LOCKED`).
- Its quantity may not drop below what has moved (`TRANSFER_ADVICE_QUANTITY_BELOW_MOVED`).
- A line that a transfer links cannot be removed (`TRANSFER_ADVICE_LINE_LINKED`).
- The transfer advice keeps at least one line (`TRANSFER_ADVICE_LAST_LINE`). This is judged
  after the whole call, so you can replace an only line.
- When every line has moved its quantity, the transfer advice closes.

#### Errors

- An error about one item names the item's index in its list, in `extensions.removeIndex`,
  `extensions.updateIndex` or `extensions.addIndex`.
- A refusal is `CONFLICT` with the reason in `extensions.reason`. A transfer advice that is
  not `OPEN` returns `TRANSFER_ADVICE_STATUS`.

#### Good to know

- The state `AWAITING` does not mean that nobody works on the transfer advice. A warehouse
  worker may already be scanning it into a draft transfer.

> An error whose path runs below this field does not mean the call failed: the change was
> applied, so do not retry. See [`Mutation`](/chameleoon-max/mutations).

Costs 1 point plus 1 per line removed, changed or added and 1 per parameter set or removed,
plus its selection.

## Arguments

- `id`: [`UUID!`](/chameleoon-max/type/uuid) · required
- `input`: [`UpdatePublicTransferAdviceInput!`](/chameleoon-max/type/update-public-transfer-advice-input) · required

## Returns

[`UpdatePublicTransferAdviceResult!`](/chameleoon-max/type/update-public-transfer-advice-result)

## Example

**Mutation**

```graphql
mutation updateTransferAdvice($id: UUID!, $input: UpdatePublicTransferAdviceInput!) {
  updateTransferAdvice(id: $id, input: $input) {
    applied
    advice {
      id
      number
      status
      state
      sourceWarehouseId
      targetWarehouseId
    }
  }
}
```

**Variables**

```json
{
  "id": "00000000-0000-4000-8000-000000000001",
  "input": {
    "requestId": "example"
  }
}
```

**Response**

```json
{
  "data": {
    "updateTransferAdvice": {
      "applied": true,
      "advice": {
        "id": "00000000-0000-4000-8000-000000000001",
        "number": "example",
        "status": "DRAFT",
        "state": "DRAFT",
        "sourceWarehouseId": "00000000-0000-4000-8000-000000000001",
        "targetWarehouseId": "00000000-0000-4000-8000-000000000001"
      }
    }
  }
}
```

Values are illustrative: replace IDs and codes with your own before you send the call.
