# Add or remove leads (/api-reference/campaigns/updateCampaignLeads)

## PUT /api/v1/campaigns/{campaign_id}/leads

Operation ID: `updateCampaignLeads`
Add or remove leads
New leads are dialed automatically if the campaign is running. Removed leads keep their call history. A lead already on the campaign, or a number already on it, is skipped.

### Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `campaign_id` | path | yes | Campaign ID. |

### Request body

`application/json` (required)

```json
{
  "additionalProperties": true,
  "description": "Leads to add to or remove from a campaign.",
  "properties": {
    "added": {
      "description": "Lead IDs to add. Removed leads are added back.",
      "items": {
        "format": "uuid",
        "type": "string"
      },
      "title": "Added",
      "type": "array"
    },
    "confirmRemovedContacted": {
      "default": false,
      "description": "Required to remove leads that were already called; otherwise the request returns 409 `campaign_leads_need_confirmation` with their IDs.",
      "title": "Confirmremovedcontacted",
      "type": "boolean"
    },
    "removed": {
      "description": "Lead IDs to remove.",
      "items": {
        "format": "uuid",
        "type": "string"
      },
      "title": "Removed",
      "type": "array"
    }
  },
  "title": "CampaignLeadsChange",
  "type": "object"
}
```

Example:

```json
{
  "added": [
    "5a1d2c3b-4e5f-4a6b-8c7d-9e0f1a2b3c4d"
  ],
  "removed": []
}
```

### Responses

#### 200 OK

Example (example):

```json
{
  "added": 1,
  "campaign": {
    "id": "3f6c1b2a-7d4e-4a1b-9c2d-5e6f7a8b9c0d"
  },
  "dialScheduled": true,
  "message": "Updated",
  "reactivated": 0,
  "removed": 0,
  "success": true
}
```

#### 401 Unauthorized: `api_key_expired`, `invalid_api_key`, `unauthenticated`.

Example (The API key has expired.):

```json
{
  "detail": "The API key has expired.",
  "error": {
    "code": "api_key_expired",
    "docUrl": "https://docs.callmitra.ai/errors/api_key_expired",
    "message": "The API key has expired.",
    "param": null,
    "requestId": "req_5f1c2e9b7a3d4c0e8b6a1f2d3c4b5a69",
    "type": "authentication_error"
  }
}
```

Example (The API key is invalid or has been revoked.):

```json
{
  "detail": "The API key is invalid or has been revoked.",
  "error": {
    "code": "invalid_api_key",
    "docUrl": "https://docs.callmitra.ai/errors/invalid_api_key",
    "message": "The API key is invalid or has been revoked.",
    "param": null,
    "requestId": "req_5f1c2e9b7a3d4c0e8b6a1f2d3c4b5a69",
    "type": "authentication_error"
  }
}
```

Example (Authentication required.):

```json
{
  "detail": "Authentication required.",
  "error": {
    "code": "unauthenticated",
    "docUrl": "https://docs.callmitra.ai/errors/unauthenticated",
    "message": "Authentication required.",
    "param": null,
    "requestId": "req_5f1c2e9b7a3d4c0e8b6a1f2d3c4b5a69",
    "type": "authentication_error"
  }
}
```

#### 403 Forbidden: `api_key_scope_denied`, `permission_denied`.

Example (The API key does not have the scope required for this request.):

```json
{
  "detail": "The API key does not have the scope required for this request.",
  "error": {
    "code": "api_key_scope_denied",
    "docUrl": "https://docs.callmitra.ai/errors/api_key_scope_denied",
    "message": "The API key does not have the scope required for this request.",
    "param": null,
    "requestId": "req_5f1c2e9b7a3d4c0e8b6a1f2d3c4b5a69",
    "type": "permission_error"
  }
}
```

Example (You do not have permission to perform this action.):

```json
{
  "detail": "You do not have permission to perform this action.",
  "error": {
    "code": "permission_denied",
    "docUrl": "https://docs.callmitra.ai/errors/permission_denied",
    "message": "You do not have permission to perform this action.",
    "param": null,
    "requestId": "req_5f1c2e9b7a3d4c0e8b6a1f2d3c4b5a69",
    "type": "permission_error"
  }
}
```

#### 404 Not found: `campaign_not_found`, `lead_not_found`.

Example (Campaign not found.):

```json
{
  "detail": "Campaign not found.",
  "error": {
    "code": "campaign_not_found",
    "docUrl": "https://docs.callmitra.ai/errors/campaign_not_found",
    "message": "Campaign not found.",
    "param": null,
    "requestId": "req_5f1c2e9b7a3d4c0e8b6a1f2d3c4b5a69",
    "type": "not_found_error"
  }
}
```

Example (Lead not found.):

```json
{
  "detail": "Lead not found.",
  "error": {
    "code": "lead_not_found",
    "docUrl": "https://docs.callmitra.ai/errors/lead_not_found",
    "message": "Lead not found.",
    "param": null,
    "requestId": "req_5f1c2e9b7a3d4c0e8b6a1f2d3c4b5a69",
    "type": "not_found_error"
  }
}
```

#### 409 Conflict: `campaign_leads_need_confirmation`, `lead_call_in_progress`.

Example (Some leads were already contacted in this campaign.):

```json
{
  "detail": "Some leads were already contacted in this campaign.",
  "error": {
    "code": "campaign_leads_need_confirmation",
    "docUrl": "https://docs.callmitra.ai/errors/campaign_leads_need_confirmation",
    "message": "Some leads were already contacted in this campaign.",
    "param": null,
    "requestId": "req_5f1c2e9b7a3d4c0e8b6a1f2d3c4b5a69",
    "type": "conflict_error"
  }
}
```

Example (Lead already has an active call.):

```json
{
  "detail": "Lead already has an active call.",
  "error": {
    "code": "lead_call_in_progress",
    "docUrl": "https://docs.callmitra.ai/errors/lead_call_in_progress",
    "message": "Lead already has an active call.",
    "param": null,
    "requestId": "req_5f1c2e9b7a3d4c0e8b6a1f2d3c4b5a69",
    "type": "conflict_error"
  }
}
```

#### 422 Invalid parameters: `parameter_invalid`.

Example (One or more parameters are invalid.):

```json
{
  "detail": [
    {
      "loc": [
        "body",
        "phone"
      ],
      "msg": "Field required",
      "type": "missing"
    }
  ],
  "error": {
    "code": "parameter_invalid",
    "docUrl": "https://docs.callmitra.ai/errors/parameter_invalid",
    "message": "One or more parameters are invalid.",
    "param": "phone",
    "requestId": "req_5f1c2e9b7a3d4c0e8b6a1f2d3c4b5a69",
    "type": "invalid_request_error"
  }
}
```

#### 429 Too many requests: `rate_limit_exceeded`.

Example (Too many requests. Slow down and retry later.):

```json
{
  "detail": "Too many requests. Slow down and retry later.",
  "error": {
    "code": "rate_limit_exceeded",
    "docUrl": "https://docs.callmitra.ai/errors/rate_limit_exceeded",
    "message": "Too many requests. Slow down and retry later.",
    "param": null,
    "requestId": "req_5f1c2e9b7a3d4c0e8b6a1f2d3c4b5a69",
    "type": "rate_limit_error"
  }
}
```

#### 500 Server error: `internal_error`.

Example (Something went wrong on our side.):

```json
{
  "detail": "Something went wrong on our side.",
  "error": {
    "code": "internal_error",
    "docUrl": "https://docs.callmitra.ai/errors/internal_error",
    "message": "Something went wrong on our side.",
    "param": null,
    "requestId": "req_5f1c2e9b7a3d4c0e8b6a1f2d3c4b5a69",
    "type": "api_error"
  }
}
```

### Error codes

- [`api_key_expired`](/errors/api_key_expired)
- [`invalid_api_key`](/errors/invalid_api_key)
- [`unauthenticated`](/errors/unauthenticated)
- [`api_key_scope_denied`](/errors/api_key_scope_denied)
- [`permission_denied`](/errors/permission_denied)
- [`campaign_not_found`](/errors/campaign_not_found)
- [`lead_not_found`](/errors/lead_not_found)
- [`campaign_leads_need_confirmation`](/errors/campaign_leads_need_confirmation)
- [`lead_call_in_progress`](/errors/lead_call_in_progress)
- [`parameter_invalid`](/errors/parameter_invalid)
- [`rate_limit_exceeded`](/errors/rate_limit_exceeded)
- [`internal_error`](/errors/internal_error)
