# createSalesOrder mutation


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

Creates a confirmed sales order from an order placed in an external source, such as an
e-shop. Call it once per order, when the customer places the order.

The call runs in one transaction, and either all of it happens or none of it:

- MAX finds or adds the customer and their addresses.
- MAX resolves every item against the catalogue and keeps your prices as sent.
- MAX reserves stock.
- MAX records what was paid.

The new order has the status `CONFIRMED`. To change it later, use
[`updateSalesOrderAddresses`](/chameleoon-max/mutation/update-sales-order-addresses), [`updateSalesOrderDetails`](/chameleoon-max/mutation/update-sales-order-details),
[`updateSalesOrderItems`](/chameleoon-max/mutation/update-sales-order-items), [`markSalesOrderPaid`](/chameleoon-max/mutation/mark-sales-order-paid) or
[`cancelSalesOrder`](/chameleoon-max/mutation/cancel-sales-order).

#### Permissions

- Requires the `order.write`, `order.read` and `partner.read` permissions.
- Adding an address to the customer's address book also requires `partner.write`.
- Sending `externalIssue` also requires `stock.sync` and `integration.read`.

#### Repeated calls

`source` and `externalId` identify the order. A repeat with the same pair changes nothing and
returns the existing order with `created: false`. If the repeat differs from the first call,
it also returns the warning `DUPLICATE_WITH_DIFFERENT_CONTENT`. A repeat does not return the
first call's other warnings again: read `SalesOrder.exceptions` for the lasting problems.

#### Errors

MAX returns every input error that leaves nothing to store at once, each as a `VALIDATION`
error that names its field. Nothing is created.

#### Orders that need a review

MAX still creates an order that it can store but that a user in MAX must check. Each
problem is listed in the order's `exceptions` and returned as a warning with the same code.
When a problem blocks the order, the order is still `CONFIRMED` and its stock is reserved, but
it is blocked with the reason `NEEDS_REVIEW` until a user in MAX looks at it.

| Code | Blocks the order | What MAX does |
| --- | --- | --- |
| `PAYMENT_METHOD_UNKNOWN` | Yes | `paymentMethod` was not sent. MAX stores `BANK_TRANSFER` in its place. |
| `TOTAL_MISMATCH` | Yes | `expectedTotal` differs from the MAX total. MAX keeps its own sums. |
| `LINE_TOTAL_MISMATCH` | Yes | An item's `lineTotal` differs from the MAX line total. |
| `UNIT_UNKNOWN` | Yes | An item's `unit` is not one of its product's units. MAX uses the base unit. |
| `PREFERRED_WAREHOUSE_IGNORED` | Yes | `preferredWarehouseId` cannot be used. The order has no preferred warehouse. |
| `CARRIER_PROFILE_UNKNOWN` | Yes | `carrier` names a well-formed pair that a fresh, authoritative Chameleoon catalogue does not contain. The order's `carrier` reads null until a user in MAX repairs the order. |
| `CARRIER_PROFILE_UNVERIFIED` | Yes | MAX could not verify `carrier` against the catalogue. The order's `carrier` reads null until a user in MAX repairs the order. |
| `PRODUCT_NOT_FOUND` | No | The line is kept unlinked. |
| `PRODUCT_ARCHIVED` | No | The line is kept unlinked. |
| `UNIT_NOT_VERIFIED` | No | The line is unlinked and you sent a `unit`. MAX cannot check the unit, so it ignores it and keeps the quantity in the product's base unit. |
| `PRODUCT_AMBIGUOUS` | No | Several products carry the EAN. The line is kept unlinked. The warning names the products' SKUs, but only in this call and only to a caller that may read the catalogue. The stored exception carries the EAN and the number of products that carry it (data `ean`, `count`), so a user in MAX can find them by searching the EAN. |
| `SET_CONTENTS_MISSING` | No | The product is a set sold as its components (`setMode` `EXPLODED`), but MAX cannot split it: the set has no components, a component is archived or is a set itself, or the quantity is not a whole number of sets. The data `reason` is `NO_COMPONENTS`, `ARCHIVED_COMPONENT`, `NESTED_SET` or `FRACTIONAL_QUANTITY`. The line is kept unlinked under its `sku`. |
| `VAT_DESTINATION_NOT_EU` | No | `vatDestinationCountry` is not an EU state. The order has no stated VAT regime. |

A user links an unlinked line in MAX. A set's line links itself once its contents are fixed.

#### Warnings

These codes are warnings only. They describe this call only.

- `DUPLICATE_WITH_DIFFERENT_CONTENT`
- `CUSTOMER_MATCHED_BY_REGISTRATION_ID`, `CUSTOMER_MATCHED_BY_EMAIL`,
  `CUSTOMER_MATCHED_SEVERAL`
- `ITEM_CONVERTED_TO_CHARGE`, `ZERO_PRICE`, `ORIGINAL_PRICE_INCONSISTENT`
- `PAYMENT_REFERENCE_TAKEN`
- `EXTERNAL_ISSUE_ITEM_UNLINKED` (field `items[i].externallyIssuedQuantity`): the item is kept
  unlinked, so none of it was recorded as externally issued. Report it with
  [`reportExternalIssue`](/chameleoon-max/mutation/report-external-issue) once a user in MAX links it.

#### External issue

`externalIssue` records, in the same transaction, that an externally managed warehouse already
took the order's goods off its stock with one of its documents. Its rules and errors are on
[`ExternalIssueInput`](/chameleoon-max/type/external-issue-input).

#### Good to know

- `orderedAt` is on your clock. The order's `number` and `confirmedAt` are on the MAX clock.

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

## Arguments

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

## Returns

[`CreateSalesOrderResult!`](/chameleoon-max/type/create-sales-order-result)

## Example

**Mutation**

```graphql
mutation createSalesOrder($input: CreateSalesOrderInput!) {
  createSalesOrder(input: $input) {
    salesOrder {
      id
      number
      status
      legalEntityId
      source
      externalId
    }
    created
    warnings {
      code
      message
      field
    }
  }
}
```

**Variables**

```json
{
  "input": {
    "source": "example",
    "externalId": "example",
    "orderedAt": "2026-01-01T00:00:00Z",
    "currencyCode": "example",
    "pricesIncludeVat": true,
    "customer": {
      "id": "00000000-0000-4000-8000-000000000001"
    },
    "billingAddress": {
      "street": "example",
      "city": "example",
      "postalCode": "example",
      "countryCode": "example"
    },
    "items": [
      {
        "name": "example",
        "quantity": "10.00",
        "unitPrice": "10.00",
        "vatPercent": "10.00"
      }
    ]
  }
}
```

**Response**

```json
{
  "data": {
    "createSalesOrder": {
      "salesOrder": {
        "id": "00000000-0000-4000-8000-000000000001",
        "number": "example",
        "status": "DRAFT",
        "legalEntityId": "00000000-0000-4000-8000-000000000001",
        "source": "example",
        "externalId": "example"
      },
      "created": true,
      "warnings": [
        {
          "code": "example",
          "message": "example",
          "field": "example"
        }
      ]
    }
  }
}
```

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