# setProductVariantExternalRef mutation


`setProductVariantExternalRef` 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 variant's reference in an external source: the variant's id in that system under
the id of its product there, such as an e-shop's variant id or OBERON's card id. Call it when
you link a variant in MAX to its record in your system.

A variant has at most one reference per external source. A different `externalId` or
`parentExternalId` replaces the variant's earlier reference in that external source. The call writes
no event and no revision of the product.

#### Permissions

Requires the `integration.read`, `item.read` and `item.write` permissions.

#### Repeated calls

A repeat with the same `externalId`, the same `parentExternalId` and the same number changes
nothing and returns `changed: false`.

#### Errors

| Code | Reason | When |
| --- | --- | --- |
| `NOT_FOUND` | | The variant does not exist. |
| `NOT_FOUND` | `SOURCE_NOT_FOUND` | No external source has the code (field `input.source`). |
| `CONFLICT` | `SOURCE_ARCHIVED` | The external source is archived. |
| `CONFLICT` | `REF_TAKEN` | Another variant holds the `externalId` in the external source, under any parent. An order line names a variant by its id alone. |
| `VALIDATION` | | `input.externalId` or `input.parentExternalId` is blank, or one of `input.externalId`, `input.parentExternalId` and `input.externalNumber` is too long. The error names the field. |

The reason is in `extensions.reason`.

> 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`: [`ProductVariantExternalRefInput!`](/chameleoon-max/type/product-variant-external-ref-input) · required

## Returns

[`ProductVariantExternalRefResult!`](/chameleoon-max/type/product-variant-external-ref-result)

## Example

**Mutation**

```graphql
mutation setProductVariantExternalRef($id: UUID!, $input: ProductVariantExternalRefInput!) {
  setProductVariantExternalRef(id: $id, input: $input) {
    productVariant {
      id
      sku
      isDefault
      archivedAt
      ean
      weightG
    }
    changed
  }
}
```

**Variables**

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

**Response**

```json
{
  "data": {
    "setProductVariantExternalRef": {
      "productVariant": {
        "id": "00000000-0000-4000-8000-000000000001",
        "sku": "example",
        "isDefault": true,
        "archivedAt": "2026-01-01T00:00:00Z",
        "ean": "example",
        "weightG": 1
      },
      "changed": true
    }
  }
}
```

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