# Start a bulk reassignment (/docs/api-reference/scheduling-reassignments/create-scheduling-reassignment)

Moves up to 5,000 bookings in the background, each on its own, so one that can't move never holds up the rest. Nothing's ever cancelled: a booking nobody can take stays where it is, and its item says so. It answers at once: follow the run by its id, or wait for `scheduling.reassignment.completed`.

`POST https://api.coss.com/v1/scheduling/reassignments`

Authenticate with your API key as a bearer token (`Authorization: Bearer coss_test_…`). Responses are JSON with snake_case fields; errors are `{ error: { type, code, message, param?, issues?, request_id } }` (https://coss.com/docs/api-reference/errors.md).

## Headers

- `Idempotency-Key` (string, 1-256 characters): Makes retries safe: a repeated request with the same key and body returns the original run instead of starting another, for 24 hours. 1-256 characters.

## Request body

- `selection` (object, required)
  - `host` (string): This host's bookings, by id or uid.
  - `out_of_office` (string): The bookings that fall in this entry.
  - `booking_ids` (string[], at most 5000 items)
  - `series` (string): A series' occurrences still to come.
  - `start_after` (string): An ISO 8601 instant with an offset.
  - `start_before` (string): An ISO 8601 instant with an offset.
  - `event_types` (string[], at most 100 items)
  - `external_conflict` (boolean): Only those with something else on the host's calendar at that time.
- `strategy` (object, default {})
  - `to_host` (string): Give them all to this host.
  - `preferred_hosts` (string[], at most 20 items): Try these first, in order.
  - `otherwise` ("auto" | "leave"): After `preferred_hosts`: `auto` picks the fairest who's free, `leave` keeps it where it is.
  - `assignments` (object[], at most 5000 items): Who each goes to: a preview, with your changes.
    - `booking` (string, required)
    - `to_host` (string, required)
    - `from_host` (string)
- `reason_code` ("host_unavailable" | "out_of_office" | "workload" | "customer_request" | "offboarding" | "other", required)
- `note` (string, at most 500 characters): Why, in your words: required with an override of someone's availability.
- `overrides` (("any_host" | "out_of_office" | "outside_availability" | "host_busy" | "limit_reached" | "calendar_unverified")[], at most 6 items)
- `notify` (object)
  - `attendees` (boolean): Tell attendees. Default: true.
  - `hosts` ("digest" | "each" | "none"): `digest` (the default) sends each host one email for the run.

## Example request

TypeScript (the `coss` package):

```ts
import { Coss } from "coss";

const coss = new Coss({
  apiKey: process.env.COSS_API_KEY,
  baseUrl: "https://api.coss.com",
});

const { data, error } = await coss.scheduling.reassignments.create({
  selection: {
    out_of_office: "ooo_01kd2m9a0b1c2d3e4f5g6h7j8m",
  },
  strategy: {
    preferred_hosts: [
      "doctor_518",
    ],
  },
  reason_code: "out_of_office",
});
```

HTTP:

```sh
curl -X POST "https://api.coss.com/v1/scheduling/reassignments" \
  -H "Authorization: Bearer $COSS_API_KEY" \
  -H "Idempotency-Key: welcome-user-123" \
  -H "Content-Type: application/json" \
  -d '{
  "selection": {
    "out_of_office": "ooo_01kd2m9a0b1c2d3e4f5g6h7j8m"
  },
  "strategy": {
    "preferred_hosts": [
      "doctor_518"
    ]
  },
  "reason_code": "out_of_office"
}'
```

## Response 202

The run, waiting to start.

- `object` ("scheduling.reassignment", required)
- `id` (string, required)
- `status` ("pending" | "running" | "completed" | "cancelled", required)
- `reason_code` ("host_unavailable" | "out_of_office" | "workload" | "customer_request" | "offboarding" | "other", required)
- `out_of_office` (string | null, required)
- `undo_of` (string | null, required)
- `counts` (object, required)
  - `total` (number, required)
  - `pending` (number, required)
  - `reassigned` (number, required)
  - `skipped` (number, required): They'd moved on since it was selected.
  - `no_candidate` (number, required): Nobody could take them: they stayed.
  - `failed` (number, required)
  - `cancelled` (number, required)
- `created_at` (string, required)
- `started_at` (string | null, required)
- `finished_at` (string | null, required)

Example:

```json
{
  "object": "scheduling.reassignment",
  "id": "reasn_01kd2m9a0b1c2d3e4f5g6h7j8m",
  "status": "completed",
  "reason_code": "out_of_office",
  "out_of_office": "ooo_01kd2m9a0b1c2d3e4f5g6h7j8m",
  "undo_of": null,
  "counts": {
    "total": 12,
    "pending": 0,
    "reassigned": 11,
    "skipped": 0,
    "no_candidate": 1,
    "failed": 0,
    "cancelled": 0
  },
  "created_at": "2027-01-01T10:00:00.000Z",
  "started_at": "2027-01-01T10:00:01.000Z",
  "finished_at": "2027-01-01T10:00:09.000Z"
}
```

## Errors

- `400`: The body is not valid JSON (`invalid_json`). Also when the `Coss-Version` header names an unknown API version (`invalid_api_version`).
- `401`: The API key is missing, invalid, revoked or expired (`authentication_error`).
- `403`: The API key lacks the permission this endpoint needs (`permission_error`), or its organization is suspended (`organization_suspended`).
- `404`: Nothing with this id or uid exists in the environment (`not_found`).
- `409`: A request with this key is still running (`idempotency_in_progress`).
- `415`: The body is not sent as `application/json` (`unsupported_media_type`).
- `422`: The selection or strategy doesn't make sense, or covers too many bookings (`invalid_reassignment`).
- `429`: Too many requests with this API key (`rate_limited`), or too many requests with invalid keys from this address (`too_many_failed_authentications`). Retry after `Retry-After` seconds. Successful responses carry `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` (seconds until the limit is fully restored).
- `500`: Unexpected server error (`api_error` / `internal_error`).
- `503`: The API key could not be verified right now; retry (`service_unavailable`).