# setPartnerExternalRef mutation


`setPartnerExternalRef` 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 partner's reference in an external source: the partner's id in that system, such
as an e-shop's customer id or OBERON's firm id. Call it when you link a partner in MAX to its
record in your system.

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

#### Permissions

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

#### Repeated calls

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

#### Errors

| Code | Reason | When |
| --- | --- | --- |
| `NOT_FOUND` | | The partner does not exist, is erased, or your API key cannot see it. |
| `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 partner holds the `externalId` in the external source. |
| `VALIDATION` | | `input.externalId` is blank, or `input.externalId` or `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`: [`PartnerExternalRefInput!`](/chameleoon-max/type/partner-external-ref-input) · required

## Returns

[`PartnerExternalRefResult!`](/chameleoon-max/type/partner-external-ref-result)

## Example

**Mutation**

```graphql
mutation setPartnerExternalRef($id: UUID!, $input: PartnerExternalRefInput!) {
  setPartnerExternalRef(id: $id, input: $input) {
    partner {
      id
      code
      name
      registrationId
      taxId
      vatId
    }
    changed
  }
}
```

**Variables**

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

**Response**

```json
{
  "data": {
    "setPartnerExternalRef": {
      "partner": {
        "id": "00000000-0000-4000-8000-000000000001",
        "code": "example",
        "name": "example",
        "registrationId": "example",
        "taxId": "example",
        "vatId": "example"
      },
      "changed": true
    }
  }
}
```

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