# setTransferExternalRef mutation


`setTransferExternalRef` 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 the transfer's reference in an external source: the record that another system made of
the transfer. Call it after your system has recorded the transfer.

#### Permissions

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

#### Repeated calls

The same `externalId` with the same number is a repeat and returns `changed: false`.

#### How references are shaped

- A system with a native transfer makes one record of it. Send one reference without a `side`.
- OBERON makes two notes, a release and a receipt. Send one reference per side, `OUT` and
  `IN`, with its GUID as `externalId` and its number as `externalNumber`.
- In one external source, a transfer has either the one reference without a side or the sided
  ones, never both. A write of the other shape is `VALIDATION` (field `input.side`) until the
  references there are removed with [`removeTransferExternalRef`](/chameleoon-max/mutation/remove-transfer-external-ref), each side on its
  own.
- A different `externalId` replaces the transfer's earlier reference in that external source
  (on that side).
- The call writes no event and no revision of the transfer.

#### Errors

The reason is in `extensions.reason`.

| Code | Reason | When |
| --- | --- | --- |
| `NOT_FOUND` | | There is no such transfer, it is a draft, or your API key cannot see it. |
| `NOT_FOUND` | `SOURCE_NOT_FOUND` (field `input.source`) | There is no such external source. |
| `CONFLICT` | `SOURCE_ARCHIVED` | The external source is archived. |
| `CONFLICT` | `REF_TAKEN` | Another transfer holds that `externalId` (on that side) in the external source. |
| `VALIDATION` | | The id is blank, or the id or number is too long (field `input.externalId` or `input.externalNumber`). |

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

## Arguments

- `id`: [`UUID!`](/chameleoon-max/type/uuid) · required
- `input`: [`TransferExternalRefInput!`](/chameleoon-max/type/transfer-external-ref-input) · required

## Returns

[`TransferExternalRefResult!`](/chameleoon-max/type/transfer-external-ref-result)

## Example

**Mutation**

```graphql
mutation setTransferExternalRef($id: UUID!, $input: TransferExternalRefInput!) {
  setTransferExternalRef(id: $id, input: $input) {
    transfer {
      stockVersion
      id
      number
      status
      version
      effectiveAt
    }
    changed
  }
}
```

**Variables**

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

**Response**

```json
{
  "data": {
    "setTransferExternalRef": {
      "transfer": {
        "stockVersion": "example",
        "id": "00000000-0000-4000-8000-000000000001",
        "number": "example",
        "status": "OPEN",
        "version": 1,
        "effectiveAt": "2026-01-01T00:00:00Z"
      },
      "changed": true
    }
  }
}
```

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