# Submit one or more backfill requests

`POST https://api.koil.co/v1/backfill-requests`

Submit one or more backfill requests. Each re-delivers one collection's history on one Profile; historical items are delivered as ordinary `content.*` events; nothing is stored. Validation is atomic across the submission and every item then runs independently. Requires an `Idempotency-Key`; one run per collection per profile may be in flight at a time.

## Authorization

An API key from the Koil admin console, sent as `Authorization: Bearer <key>`. A live key starts `koil_live_` and a sandbox key `koil_sandbox_`; the key alone selects the Organization and mode. See https://docs.koil.co/concepts/authentication.

## Parameters

| Name | In | Required | Type | Description |
| --- | --- | --- | --- | --- |
| `Koil-Version` | header | yes | `"2026-12-08"` | The dated API version the request is written against; it fixes the request and response shapes. Every response echoes the version it is rendered in. |
| `Idempotency-Key` | header | yes | string | A unique key for this request, scoped to the Organization and operation. Retrying with the same key and payload returns the first result instead of repeating the work, or runs a request that failed again; the same key with a different payload is refused with `409 conflict`. Keys expire 24 hours after first use, and a request still in flight after 15 minutes releases its key to a retry with the same payload. |

## Request body

`application/json`

- `backfillRequests` (array of object, required) (min 1 items, max 100 items): The runs to start. Each item becomes its own backfill request with its own progress; a profile onboarding lists its collections, an incident recovery lists its profiles.
  - `profileId` (string, required) (min length 1): Koil Profile identifier.
  - `collection` (string, required) (min length 1): Fully qualified collection to backfill, e.g. `instagram.media.posts`. It must belong to the profile's platform and declare a supported backfill capability.
  - `metadata` (object): Your own key-value pairs, up to 50 keys of at most 40 characters with string values of at most 500. An update merges into what is stored, and a key set to `""` is removed.
- `since` (string, date-time): Oldest item time to emit, applied to every item. Omit for no lower bound, in which case each run is bounded only by `maxItems` and the platform's history.
- `maxItems` (integer) (min 1, max 10000, default `1000`): Hard cap on emitted events per item, not in total. A run that stops here finishes `partial`.

Every named shape is in the [OpenAPI document](https://docs.koil.co/openapi.json) under `components.schemas`.

## Example

Re-deliver a profile's posts and stories since June:

```bash
curl -X POST "https://api.koil.co/v1/backfill-requests" \
  -H "Authorization: Bearer $KOIL_API_KEY" \
  -H "Koil-Version: 2026-12-08" \
  -H "Idempotency-Key: <Idempotency-Key>" \
  -H "Content-Type: application/json" \
  -d '{"backfillRequests":[{"profileId":"prof_123","collection":"instagram.media.posts"},{"profileId":"prof_123","collection":"instagram.stories.posts"}],"since":"2026-06-01T00:00:00Z","maxItems":1000}'
```

## Response 202

Accepted; `backfillRequests` has one entry per submitted item.

- `backfillRequests` (array of object, required)
  - `kind` (`"backfill_request"`, required): The kind of resource this is.
  - `mode` (one of `"live"`, `"sandbox"`, required): Which mode the resource belongs to. Live and sandbox resources are separate: a key reads and writes only its own mode's.
  - `id` (string, required) (min length 1): Koil backfill request identifier.
  - `profileId` (string, required) (min length 1): Koil Profile identifier.
  - `collection` (string, required) (min length 1)
  - `since` (string, date-time)
  - `maxItems` (integer, required)
  - `status` (one of `"pending"`, `"running"`, `"completed"`, `"partial"`, `"failed"`, required)
  - `stopReason` (one of `"exhausted"`, `"reached_since"`, `"capped"`)
  - `emitted` (integer, required)
  - `fetched` (integer, required)
  - `skipped` (integer, required)
  - `oldestEmittedAt` (string, date-time)
  - `error` (object)
    - `code` (one of `"validation_error"`, `"not_supported"`, `"unauthorized"`, `"quota_exceeded"`, `"permission_denied"`, `"scope_insufficient"`, `"connection_invalid"`, `"not_found"`, `"conflict"`, `"rate_limit_exceeded"`, `"platform_rate_limit"`, `"internal"`, `"service_unavailable"`, required): Stable error code. `validation_error` (400), `not_supported` (400), `unauthorized` (401), `quota_exceeded` (402), `permission_denied` (403), `scope_insufficient` (403), `connection_invalid` (403), `not_found` (404), `conflict` (409), `rate_limit_exceeded` (429), `platform_rate_limit` (429), `internal` (500, 502, 504), `service_unavailable` (503).
    - `message` (string, required): Human-readable summary.
    - `meta` (object, required): Structured detail; the keys depend on `code`.
      - `violations` (array of object): Every problem with the request. Always present on a `validation_error`.
        - `code` (string, required): Stable violation code, such as `missing_field`, `unknown_field`, `schema_error`, `invalid_value` or `invalid_combination`.
        - `path` (string, required): JSON pointer into the request: path, query and body fields share one pointer space (`/cursor`, `/publishRequests/0/args/text`), a header is `/headers/<lowercase name>`, and `""` is the request as a whole.
        - `message` (string, required): Human-readable explanation.
      - `budgets` (array of string): On a `rate_limit_exceeded`: every budget that refused the request: `organization` (every authenticated request), `profile` (a request that acts on a Profile, one budget per Profile) or `client_address` (requests with no key or a rejected one). Koil may add budgets; treat an unknown one as covering the whole Organization.
      - `profileIds` (array of string): On a `rate_limit_exceeded` whose `budgets` include `profile`: the Profiles whose budget is spent. Requests that act on other Profiles are unaffected.
      - `required` (array of string): On a `permission_denied`: the API key permissions the operation requires that the key lacks.
      - `limit` (integer): On a `quota_exceeded`: the cap that was reached.
      - `resourceType` (string): On a `not_found` or a `conflict` over an existing resource: the kind of resource, such as `profile` or `connection`.
      - `resourceId` (string): With `resourceType`: the id of the resource not found or already there.
      - `reason` (string): On a failed publish or backfill request, or a failed Connect Session, that Koil failed itself, not the platform: why, such as `media_incompatible`, `media_transform_not_entitled` or `subject_mismatch` (a reconnect authorized a different platform account than the Connection's).
      - `refusalReason` (one of `"messaging_window_closed"`, `"recipient_rate_limited"`, `"recipient_unavailable"`, `"publishing_limit_reached"`): Why the platform refused, where the code alone does not say what to do. `messaging_window_closed`: The platform takes a message to this person only inside a window that has closed: WhatsApp's 24-hour customer service window, the Messenger and Instagram messaging window, or TikTok's allowance since the person last wrote. It reopens when the person writes again. `recipient_rate_limited`: Too many messages to this one person in a short time; messages to others are unaffected. Retry after `Retry-After`. `recipient_unavailable`: The person cannot receive messages from this Profile: they blocked it or deactivated their account, or, on WhatsApp, the number has no account or an outdated app. Retrying does not help. `publishing_limit_reached`: The account's own publishing cap on the platform is spent: Instagram's 24-hour content publishing limit, YouTube's daily upload limit, or TikTok's limit on posts. Publish again once it resets.
  - `startedAt` (string, date-time)
  - `completedAt` (string, date-time)
  - `metadata` (object, required): Your own key-value pairs, up to 50 keys of at most 40 characters with string values of at most 500. An update merges into what is stored, and a key set to `""` is removed.
  - `createdAt` (string, date-time, required)
  - `updatedAt` (string, date-time, required)

## Errors

Every error has the same shape: `{ "error": { "code", "message", "meta", "requestId" } }`. [Errors →](https://docs.koil.co/concepts/errors)

| Status | Meaning |
| --- | --- |
| 400 | `validation_error`: The request does not match the operation's input schema, fails an admission check, or the platform refused its content. `meta.violations` names every problem. `not_supported`: The platform, collection or resource does not offer this operation, such as exporting a `key` Connection's credential, which Koil never returns. |
| 401 | `unauthorized`: No API key, or a key Koil does not accept (unknown, revoked, or with a prefix that does not match its mode). |
| 404 | `not_found`: The resource does not exist in this Organization and mode. |
| 409 | `conflict`: The request collides with current state: an idempotency key reused with a different payload or still in flight, a run already in progress, a publish that has already started, or a resource that already exists (`meta.resourceType` and `meta.resourceId` name it). Retry only when the response carries `Retry-After` (the key's first request is still in flight, or a sandbox Profile's collection hasn't had its first poll), after that many seconds. |
| 429 | `rate_limit_exceeded`: Koil's own rate limit for the key, Organization, Profile, or client address is spent (`meta.budgets` names which); retry after `Retry-After` seconds. `platform_rate_limit`: The platform throttled the call or the platform quota is spent; retry after `Retry-After` seconds. |
| 500 | `internal`: Koil or the platform failed, and the status says which: 500 when Koil failed, including a platform refusing how Koil made the call; 502 when the platform failed or answered something Koil cannot use; 504 when Koil's call to the platform timed out. The message is generic; retry with backoff. |
| 503 | `service_unavailable`: A service Koil needs to accept the request (API key validation or rate limiting) is unavailable. Nothing was attempted; retry after `Retry-After` seconds. The hosting edge can deliver this as a `504` with neither this body nor `Retry-After`, so treat a `502`, `503` or `504` alike as retryable, with backoff. |
| default | Any other failure. `error.code` names it; the HTTP status follows from it. |
