# reportExternalIssue mutation


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

Records that an externally managed warehouse already took goods of the order off its stock
with one of its own documents. Call it when the external system that manages the warehouse
(see [`syncStockLevels`](/chameleoon-max/mutation/sync-stock-levels)) issues an invoice that takes goods off stock, or a credit
note that returns them, before MAX picked or dispatched the goods.

What the report does:

- The external system's stock snapshots no longer take the same goods off twice.
- The order's reservations stay.
- When MAX issues the goods itself, it offsets them against the report.
- What MAX never issues stays open on the item (`externallyIssuedOpen`). When MAX will issue
  nothing more of the order, it opens the exception `EXTERNAL_ISSUE_OPEN` for a user in MAX.
- The report never blocks the order.

> Each item's quantity is absolute for the combination of external system,
> `documentExternalId` and item. Send everything the document issued of the item, not a
> change.

#### Permissions

Requires the `stock.sync`, `integration.read`, `order.write` and `order.read` permissions.

#### Repeated calls

MAX writes only the difference against what the same document reported before. A repeat
changes nothing. Send a corrected document again with its new quantities. An order created
with `externalIssue` already holds its document's quantities.

#### Your contract

MAX cannot check these rules, so your integration must follow them:

- `effectiveAt` is on the same clock as `asOf` of [`syncStockLevels`](/chameleoon-max/mutation/sync-stock-levels): the external
  system's own clock. If the system keeps local time without a time zone (Pohoda), convert both
  values with its time zone. Otherwise MAX cannot tell whether a snapshot contains the issue.
- Send a snapshot with `asOf` only after you reported every external issue with `effectiveAt`
  at or before `asOf`. A snapshot sent before the report takes the goods off stock until the
  report arrives.
- When a corrected document no longer has an item, send the item with quantity 0.
- A repeat of [`createSalesOrder`](/chameleoon-max/mutation/create-sales-order) whose document changed in the meantime keeps the
  first quantities (`DUPLICATE_WITH_DIFFERENT_CONTENT`). Send the corrected quantities here,
  under the same `documentExternalId`.
- `documentExternalId` is the document's number in the external system (in Pohoda, the invoice
  number). It must be unique there across accounting years.
- When a document's items left several warehouses, report the document once per warehouse,
  each call with its own items. One document reports an item in one warehouse. To move the item,
  report 0 in the first warehouse.
- Report a reversal (a credit note or a cancelled invoice) as a separate document, with a
  negative quantity on the original item.
- Returns are out of scope. A credit note for goods MAX already dispatched is refused
  (`EXTERNAL_ISSUE_BELOW_ISSUED`). A reversal of an invoice whose goods MAX has not dispatched,
  or whose consignment MAX cancelled, is reported here and balances the invoice.
- MAX offsets the order's own issues against the reports, so they are not confirmed:
  [`confirmStockInExternalSystem`](/chameleoon-max/mutation/confirm-stock-in-external-system) refuses them. Sometimes MAX issues more than the
  external documents took off, for example when an invoice was cancelled before dispatch or
  covered only part of an item. Once you write that surplus into the external system with a
  document of its own, report it here under that document's id.

#### Errors

One refusal refuses the whole call.

- `NOT_FOUND` when the order or the warehouse does not exist, or your API key cannot see it.
  MAX checks the order before any item.
- `CONFLICT` with `extensions.reason` `STOCK_NOT_MASTERED` (field `warehouseId`) when no
  external system manages the warehouse.
- `CONFLICT` with `extensions.reason` `ORDER_STATUS` and `extensions.field` `salesOrder` when
  the order is a draft (confirm it first) or merged into another order (report on that one).
- `VALIDATION` on `salesOrder` when the reference names the order by neither or both of `id`
  and `source` with `externalId`.
- A refusal of the item itself names the input that named the item
  (`items[i].salesOrderItemId` or `items[i].itemExternalId`).

`CONFLICT` with `extensions.field` `items[i].quantity` and one of these reasons:

| Reason | When |
| --- | --- |
| `EXTERNAL_ISSUE_OVER_QUANTITY` | An item's reports would add up to more than its quantity. |
| `EXTERNAL_ISSUE_NEGATIVE` | An item's reports would add up to less than zero. |
| `EXTERNAL_ISSUE_BELOW_ISSUED` | A lower quantity would take back goods of the item that MAX already issued and keeps issued. |
| `EXTERNAL_ISSUE_OTHER_WAREHOUSE` | The document already reported the item in another warehouse. |

`VALIDATION` for any of these:

- A blank `documentExternalId`, or one over 128 bytes.
- An `effectiveAt` more than 15 minutes ahead of the MAX clock.
- No items, or more than 100.
- An item named by neither or both of `salesOrderItemId` and `itemExternalId`.
- An `itemExternalId` that names no item of the order, or several.
- The same item twice.
- A quantity with more than three decimals, or one that does not convert into the item's base
  units within six decimals.
- An item of another order.
- A set's own item. Report its components instead.
- An item not linked to a product.
- A warehouse of another company than the order's.

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

Costs 1 point plus 1 per item, plus its selection.

## Arguments

- `input`: [`ReportExternalIssueInput!`](/chameleoon-max/type/report-external-issue-input) · required

## Returns

[`ReportExternalIssueResult!`](/chameleoon-max/type/report-external-issue-result)

## Example

**Mutation**

```graphql
mutation reportExternalIssue($input: ReportExternalIssueInput!) {
  reportExternalIssue(input: $input) {
    salesOrder {
      id
      number
      status
      legalEntityId
      source
      externalId
    }
  }
}
```

**Variables**

```json
{
  "input": {
    "salesOrder": {
      "id": "00000000-0000-4000-8000-000000000001"
    },
    "warehouseId": "00000000-0000-4000-8000-000000000001",
    "effectiveAt": "2026-01-01T00:00:00Z",
    "documentExternalId": "example",
    "items": [
      {
        "quantity": "10.00"
      }
    ]
  }
}
```

**Response**

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

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