# updateReceiptAdvice mutation


`updateReceiptAdvice` 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` receipt advice: removes, changes and adds lines, and changes its header
terms and parameters. Call it when the supplier changes what it will deliver.

The call runs in one transaction, and either all of it happens or none of it. MAX applies
`removeLineIds`, `updateLines` and `addLines` in that order, then the header terms, then the
parameters.

#### Permissions

Requires the `advice.write` and `advice.read` permissions, with the advice in your API key's
scope.

#### Repeated calls

`requestId` makes a retry after a lost response safe. A repeat with the same `requestId` and
input changes nothing and returns `applied: false` with the advice as it is now, even if the
advice has closed since. The same `requestId` with other input, or on another advice, returns
`CONFLICT` with the reason `REQUEST_ID_REUSED`.

#### Your contract

- The supplier, the warehouse and the currency cannot change.
- A line that goods arrived against keeps its unit, and its quantity may not drop below what
  arrived.
- A line whose difference is resolved keeps its quantity.
- A line that a receipt or a handheld scan answers cannot be removed.
- The advice keeps at least one line. MAX checks this after the whole call.
- `AWAITING` does not mean that nobody works on the advice: a warehouse worker may already be
  scanning it into a draft receipt.

#### Errors

A failed item names its index in its list in `extensions.removeIndex`,
`extensions.updateIndex` or `extensions.addIndex`. The reason is in `extensions.reason`.

| Code | Reason | When |
| --- | --- | --- |
| `CONFLICT` | `ADVICE_NOT_OPEN` | The advice is not `OPEN`, for example closed or cancelled. |
| `CONFLICT` | `ADVICE_LAST_LINE` | The call would leave the advice without a line. |
| `CONFLICT` | `LINE_ANSWERED` | A line to remove is answered by a receipt or a scan. |
| `CONFLICT` | `LINE_SETTLED` | A line's quantity changes, but its difference is resolved. |
| `CONFLICT` | `LINE_UNIT_RECEIVED` | A line's unit changes, but goods arrived against it in its unit. |
| `VALIDATION` | `QUANTITY_BELOW_RECEIVED` | A line's quantity drops below what arrived. |
| `CONFLICT` | `REQUEST_ID_REUSED` | The `requestId` was used with other input or on another advice. |
| `NOT_FOUND` | | A line in `removeLineIds` or `updateLines` is not a line of this advice. |

> An error whose path runs below this field does not mean the call failed: the receipt advice
> was updated, 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`: [`UpdateReceiptAdviceInput!`](/chameleoon-max/type/update-receipt-advice-input) · required

## Returns

[`UpdateReceiptAdviceResult!`](/chameleoon-max/type/update-receipt-advice-result)

## Example

**Mutation**

```graphql
mutation updateReceiptAdvice($id: UUID!, $input: UpdateReceiptAdviceInput!) {
  updateReceiptAdvice(id: $id, input: $input) {
    applied
    advice {
      id
      number
      kind
      status
      state
      supplierId
    }
  }
}
```

**Variables**

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

**Response**

```json
{
  "data": {
    "updateReceiptAdvice": {
      "applied": true,
      "advice": {
        "id": "00000000-0000-4000-8000-000000000001",
        "number": "example",
        "kind": "DELIVERY_NOTE",
        "status": "DRAFT",
        "state": "DRAFT",
        "supplierId": "00000000-0000-4000-8000-000000000001"
      }
    }
  }
}
```

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