<!-- source: https://secondlayer.tools/docs/api-reference#backfill-deployment -->

## Queue a backfill over a block range

`POST /api/subgraphs/{name}/backfill` (self-hosted instances only)

Re-runs handlers over `fromBlock` to `toBlock`, inclusive, without dropping data. A backfill that overlaps an earlier failed or cancelled one resumes from its last committed block. Refused when the handlers apply deltas (`ctx.increment`, `ctx.update`) or read-modify-write rows (`ctx.findOne`, `ctx.findMany`), which would double-count blocks already processed; reindex those instead.

### Path parameters

| Name | Type | Description |
| --- | --- | --- |
| `name` | string, required | Subgraph name, as deployed. Lowercase letters, digits and hyphens. |

### Body

| Field | Type | Description |
| --- | --- | --- |
| `fromBlock` | integer, required | First block height to re-run, inclusive. |
| `toBlock` | integer, required | Last block height to re-run, inclusive. |

### Returns

One `SubgraphOperationQueued` object.

### Responses

- `200` Backfill queued
- `400` `fromBlock` or `toBlock` is missing, not a number, or 0 (`VALIDATION_ERROR`)
- `401` This bind requires the instance token, and it was missing or wrong
- `404` No subgraph by this name on this instance (`SUBGRAPH_NOT_FOUND`)
- `409` A reindex or backfill is already queued or running for this subgraph (`OPERATION_IN_PROGRESS`). Wait for it, or stop it first.
- `415` Missing or non-JSON `Content-Type` (`UNSUPPORTED_MEDIA_TYPE`) — writes must send `Content-Type: application/json`
- `422` The handlers apply deltas and cannot be replayed (`BACKFILL_NON_REPLAYABLE_HANDLER`)

### Example

```bash
curl -X POST http://127.0.0.1:3800/api/subgraphs/{name}/backfill \
  -H "Authorization: Bearer $INSTANCE_TOKEN" \
  --json '{
  "fromBlock": 8950000,
  "toBlock": 9000000
}'
```

```json
{
  "message": "Backfill queued for subgraph \"sbtc-flows\"",
  "fromBlock": 8950000,
  "toBlock": 9000000,
  "operationId": "9a4e7c21-0b3d-4f6a-8c15-e2d7b9f0a461",
  "status": "queued"
}
```
