# Link Tickets

> Link two LemuTickets tickets: relates to, blocks, duplicates, caused by or clones

URL: https://docs.lemuai.com/tickets-api/tickets/link

Links one ticket to another, for example to show that a delivery issue blocks a refund, or that two complaints are about the same problem.

**Endpoint:** `POST /v1/tickets/{ref}/links`

Use a key with the `tickets.write` scope. You must be able to see both tickets.

## Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `ref` | string | Yes | The ticket the link starts from: key (`SUP-1042`) or id. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `target` | string | Yes | The other ticket: key or id. |
| `kind` | string | No | How they relate, read as "this ticket *kind* target". Default `relates_to`. |

| `kind` | Meaning | Seen from the target as |
|---|---|---|
| `relates_to` | The tickets are related | `relates_to` |
| `blocks` | This ticket blocks the target | `blocked_by` |
| `duplicates` | This ticket duplicates the target | `duplicated_by` |
| `caused_by` | This ticket was caused by the target | `causes` |
| `clones` | This ticket is a copy of the target | `cloned_by` |

**Example request:**
```bash
curl -X POST https://api.tickets.lemuai.com/v1/tickets/SUP-1042/links \
  -H "Authorization: Bearer ltk_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{ "target": "SUP-1039", "kind": "caused_by" }'
```

## Response

**`201`**
```json
{
  "id": "0a2c4e6b-8d0f-4a1c-9e3b-5d7f9a1c3e5b",
  "kind": "caused_by",
  "target": "SUP-1039"
}
```

| Field | Type | Description |
|---|---|---|
| `id` | string | The link's id. |
| `kind` | string | The link kind. |
| `target` | string | The target ticket's key. |

Linking the same two tickets with the same `kind` again returns the existing link, so it is safe to retry. A new link fires the `ticket.linked` [webhook](https://docs.lemuai.com/tickets-api/webhooks) on the source ticket.

## Errors

| Status | `code` | When |
|---|---|---|
| `404` | `ticket_not_found` | Either ticket does not exist, or you cannot see it |
| `422` | `invalid_link` | A ticket cannot link to itself |
| `422` | `invalid_fields` | `target` is missing or `kind` is not one of the values above |
