# reportSalesOrderItemWriteBack mutation


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

Reports the result of writing one of the order's goods lines back to the external source.
Call it after a user changed the line in MAX and your integration wrote the change to the
external source's order.

Send one of the following:

- `externalId`: the external source's id of the item it created for the line. MAX links it as
  the external source's line, so the next change of the order from the external source matches
  it.
- `problem`: why the external source refused the line. MAX shows it as the warning
  `SHOP_ITEM_NOT_WRITTEN` on the line. This applies to a removed line too, while the external
  source still has its item.
- Neither: the line was written as it is linked (changed or removed). MAX resolves the warning,
  as linking the line would.

Name the order by `source` and `externalId`, or by its MAX `id`. With the MAX `id`, the
external order is the one this order was placed as.

#### Permissions

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

#### Errors

- `VALIDATION` for an `externalId` over 255 characters.
- `CONFLICT` when the `externalId` belongs to another line.
- `NOT_FOUND` when the order or the line 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 result was
> recorded, so do not retry. See [`Mutation`](/chameleoon-max/mutations).

## Arguments

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

## Returns

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

## Example

**Mutation**

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

**Variables**

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

**Response**

```json
{
  "data": {
    "reportSalesOrderItemWriteBack": {
      "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.
