# setIssueExternalRef mutation


`setIssueExternalRef` 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 issue's reference in an external source: the record that the external system made
of the issue. Call it after you write the issue to the external system, for example with an
OBERON note's GUID as `externalId` and its number as `externalNumber`.

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

#### Permissions

Requires the `integration.read`, `issue.read` and `issue.write` permissions, with the issue 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 issue does not exist, is a draft, 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 issue holds that `externalId` in the external source. |
| `VALIDATION` | | The id is blank, or the id or number is too long (field `input.externalId` or `input.externalNumber`). |

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

## Returns

[`IssueExternalRefResult!`](/chameleoon-max/type/issue-external-ref-result)

## Example

**Mutation**

```graphql
mutation setIssueExternalRef($id: UUID!, $input: StockDocumentExternalRefInput!) {
  setIssueExternalRef(id: $id, input: $input) {
    issue {
      stockVersion
      id
      number
      status
      version
      effectiveAt
    }
    changed
  }
}
```

**Variables**

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

**Response**

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