## Unlink a contact from a lead

`DELETE /v1/leads/:id/contacts/:relatedId`

Unlinks one contact from a lead. The lead's other contacts stay linked. The contact itself stays in the CRM.

You can restore the link with [`POST /v1/leads/:id/contacts`](/docs/entities/leads/contacts-create). To put the contact back in its previous position and make it primary again, pass its previous `sort` and `isPrimary`.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|----------|
| `id` (path) | number | yes | Lead ID. List: [`GET /v1/leads`](/docs/entities/leads/list) |
| `relatedId` (path) | number | yes | ID of the linked contact — the `contactId` value from [`GET /v1/leads/:id/contacts`](/docs/entities/leads/contacts-list) |

## Examples

### curl — personal key

```bash
curl -X DELETE "https://vibecode.bitrix24.com/v1/leads/1001321/contacts/2937" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl -X DELETE "https://vibecode.bitrix24.com/v1/leads/1001321/contacts/2937" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/leads/1001321/contacts/2937', {
  method: 'DELETE',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})

if (res.status === 204) {
  console.log('Contact unlinked')
}
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/leads/1001321/contacts/2937', {
  method: 'DELETE',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})

if (res.status === 204) {
  console.log('Contact unlinked')
}
```

## Response

On successful unlinking, the API returns HTTP status `204 No Content` with an empty body. Success is indicated by the status code, not by the content.

## Response example

```
HTTP/1.1 204 No Content
```

## Error response example

404 — the contact is not linked to this lead:

```json
{
  "success": false,
  "error": {
    "code": "ENTITY_NOT_FOUND",
    "message": "Binding not found"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `INVALID_PARAMS` | `id` or `relatedId` is not a positive integer |
| 404 | `ENTITY_NOT_FOUND` | No contact with this ID is linked to this lead, for example because it has already been unlinked. The message is `Binding not found` |
| 404 | `ENTITY_NOT_FOUND` | No lead with this `id` exists. The message is `Not found.` |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |
| 401 | `TOKEN_MISSING` | The key has no Bitrix24 tokens attached |
| 403 | `SCOPE_DENIED` | The key does not have the `crm` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode. Unlinking requires a key with write access |
| 429 | `RATE_LIMITED` | Rate limit exceeded. Retry after the delay in the `Retry-After` header |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is unavailable. Retry the request later |

Full list of common API errors — [Errors](/docs/errors).

## Known specifics

- **Unlinking the primary contact.** If you unlink the primary contact, the first of the remaining contacts in `sort` order becomes primary. Its ID arrives in the `contactId` field of the [`GET /v1/leads/:id`](/docs/entities/leads/get) response.
- **Retrying after a lost response.** Unlinking the same contact again returns `404` with the message `Binding not found`: the link no longer exists. Check the result in the [list of lead contacts](/docs/entities/leads/contacts-list).

## See also

- [Lead contacts](/docs/entities/leads/contacts)
- [List lead contacts](/docs/entities/leads/contacts-list)
- [Link a contact to a lead](/docs/entities/leads/contacts-create)
- [Replace lead contacts](/docs/entities/leads/contacts-set)
- [Unlink all contacts from a lead](/docs/entities/leads/contacts-delete)
- [Contacts](/docs/entities/contacts)
