# cancelSalesOrder mutation


`cancelSalesOrder` 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).

Cancels the order and releases its reserved stock. Call it when the customer cancels the order
in the external source.

- Consignments that are still being prepared are cancelled with the order.
- Payments stay as they are. A refund is recorded when the money moves.

#### Permissions

Requires the `order.write` and `order.read` permissions.

#### Repeated calls

A repeat changes nothing and returns `changed: false`.

#### Errors

- `CONFLICT` once the warehouse has dispatched any part of the order, or when the order was
  merged into another or is still a draft. A user in MAX handles these cases.
- `NOT_FOUND` when the order does not exist or your API key cannot see it.

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

## Arguments

- `ref`: [`SalesOrderRefInput!`](/chameleoon-max/type/sales-order-ref-input) · required

## Returns

[`SalesOrderChangeResult!`](/chameleoon-max/type/sales-order-change-result)

## Example

**Mutation**

```graphql
mutation cancelSalesOrder($ref: SalesOrderRefInput!) {
  cancelSalesOrder(ref: $ref) {
    salesOrder {
      id
      number
      status
      legalEntityId
      source
      externalId
    }
    changed
  }
}
```

**Variables**

```json
{
  "ref": {
    "id": "00000000-0000-4000-8000-000000000001"
  }
}
```

**Response**

```json
{
  "data": {
    "cancelSalesOrder": {
      "salesOrder": {
        "id": "00000000-0000-4000-8000-000000000001",
        "number": "example",
        "status": "DRAFT",
        "legalEntityId": "00000000-0000-4000-8000-000000000001",
        "source": "example",
        "externalId": "example"
      },
      "changed": true
    }
  }
}
```

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