# Backfill history

> Re-deliver a collection's history for a Profile as ordinary content events.

Events start flowing when a profile is connected, so a new profile's inbox starts empty. A backfill request re-delivers what the platform still has — as the same `content.{collection}.created` events your destination already handles. Use it to seed a new profile, or to recover a window after your receiver was down.

Nothing is stored: Koil pages through the platform and emits each item. Event ids are derived from the item, so an item a poll or webhook already delivered, or one re-sent by a second backfill, arrives with the id you already have: deduplicating on the event `id` drops it. A backfill re-delivers items that still exist; it does not replay edits or deletions.

## Submit

Each entry in `backfillRequests` is one collection on one Profile. The collection must support backfill: its [platform page](https://docs.koil.co/platforms) and `GET /v1/collections` say which do, as `backfill.supported` with the `coverage` a run reaches. `GET /v1/profiles/{profileId}/capabilities` answers for one profile: there `backfill.supported` is also `false`, with the `reason`, when the grant lacks a scope the listing needs.

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

-   `since` bounds the oldest item emitted, for every item.
-   `maxItems` caps each item's run, not the batch.
-   Validation is atomic: an unknown, unsupported, or duplicate item (`duplicate_item`) rejects the whole submission with every problem named, and nothing starts.
-   Only one run per collection per profile may be in flight. A colliding submission is refused with `409 conflict`, listing the in-flight `backfillRequestId`s in `meta.conflicts`; poll those instead.
-   After validation each item runs independently with its own `bf_…` entry, returned with `202 Accepted`. An item that could not start comes back `failed` with an `error`; the others proceed.

## Track

`GET /v1/backfill-requests/{backfillRequestId}` reports a run's progress (`emitted`, `fetched`, `skipped`) and status. A run finishes `completed`, `partial` when it spent `maxItems` with history left, or `failed` with an `error`; `stopReason` says whether it ended because the platform had nothing more (`exhausted`), it reached `since` (`reached_since`), or it hit the cap (`capped`).

A platform rate limit pauses a run instead of failing it: the run stays `running` and resumes once the platform's limit lifts, which for a spent daily quota is the next day. It fails with `platform_rate_limit` only if the platform keeps refusing.

Rather than polling, subscribe to `backfill_request.*`: each run that started announces how it finished as `backfill_request.completed`, `backfill_request.partial`, or `backfill_request.failed`, with the run as `GET` returns it in `data` and its `backfillRequestId` and `profileId` in `context`, so a destination scoped to the profile receives it. Events are not ordered, so some of the run's content events may arrive after its outcome. These topics never count toward fair use.

The full request and response schemas are in the [API endpoints](https://docs.koil.co/openapi/backfill-requests/v1-backfill-requests-post) reference.
