# Dataset routes: backfill, refresh

URL: /code/api/dataset/verbs · Id: `page:code/api/dataset/verbs`

> The Dataset Verbs backfill, refresh as api.sb routes, with inputs, result, refusals and an example.

Reference for [Dataset](/business/nouns/dataset), one group of [Dataset routes](/code/api/dataset).

### Dataset.backfill
Backfill reads one Source of a Dataset over a past date range and records every value observed in it. [Verb page](/business/nouns/dataset/backfill?interface=api).

```text
POST /{namespace}/datasets/{dataset}/backfill
```

Path: `dataset`. Body, as JSON: the other inputs. Emits [`Dataset.backfilled`](/business/events/Dataset.backfilled).

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `dataset` | [Dataset](/business/nouns/dataset) | Yes | The Dataset. |
| `source` | [Source](/business/nouns/source) | Yes | The Source to read. |
| `from` | `date` | Yes | The first day of the range. |
| `to` | `date` | Yes | The last day of the range. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `dataset` | [Dataset](/business/nouns/dataset) | Yes | The Dataset, with the range filled. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
| `dataset` is missing, or is not a dataset | [`invalid-input`](/code/api/errors/invalid-input) | Send `dataset` as a dataset, then call it again. | None. |
| `source` is missing, or is not a source | [`invalid-input`](/code/api/errors/invalid-input) | Send `source` as a source, then call it again. | None. |
| `from` is missing, or is not a date | [`invalid-input`](/code/api/errors/invalid-input) | Send `from` as a date, then call it again. | None. |
| `to` is missing, or is not a date | [`invalid-input`](/code/api/errors/invalid-input) | Send `to` as a date, then call it again. | None. |
| The `Idempotency-Key` was sent before with another operation or other input | [`idempotency-mismatch`](/code/api/errors/idempotency-mismatch) | Send a new key for new input; reuse a key only to retry the same request. | None. |

**Example**

```bash
curl -X POST https://api.sb/ratebook.dev/datasets/dataset_UDQXk0KsJB/backfill \
  -H "Authorization: Bearer $SB_TOKEN" \
  -H "Idempotency-Key: ratebook-dataset-backfill-1" \
  -H "Content-Type: application/json" \
  -d '{"source":"source_DIdhfB6mF5","from":"2026-10-22","to":"2026-10-22"}'
```

```json
{
  "api": "https://api.sb/ratebook.dev",
  "dataset": {
    "$id": "https://api.sb/ratebook.dev/datasets/dataset_UDQXk0KsJB",
    "$type": "Dataset",
    "name": "Ratebook",
    "promise": "A rate for any US address in under 100 milliseconds.",
    "status": "draft"
  },
  "action": {
    "$id": "https://api.sb/ratebook.dev/actions/act_M5LgINdysq",
    "operation": "Dataset.backfill",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/ratebook.dev/actions/act_M5LgINdysq"
  }
}
```

### Dataset.refresh
Refresh re-reads a Dataset’s Sources now instead of on schedule, and records what changed. [Verb page](/business/nouns/dataset/refresh?interface=api).

```text
POST /{namespace}/datasets/{dataset}/refresh
```

Path: `dataset`. Body, as JSON: the other inputs. Emits [`Dataset.refreshed`](/business/events/Dataset.refreshed).

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `dataset` | [Dataset](/business/nouns/dataset) | Yes | The Dataset. |
| `source` | [Source](/business/nouns/source) | No | One Source to read; absent, every Source. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `dataset` | [Dataset](/business/nouns/dataset) | Yes | The Dataset, with `refreshedAt` set. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
| `dataset` is missing, or is not a dataset | [`invalid-input`](/code/api/errors/invalid-input) | Send `dataset` as a dataset, then call it again. | None. |
| The `Idempotency-Key` was sent before with another operation or other input | [`idempotency-mismatch`](/code/api/errors/idempotency-mismatch) | Send a new key for new input; reuse a key only to retry the same request. | None. |

**Example**

```bash
curl -X POST https://api.sb/ratebook.dev/datasets/dataset_UDQXk0KsJB/refresh \
  -H "Authorization: Bearer $SB_TOKEN" \
  -H "Idempotency-Key: ratebook-dataset-refresh-1"
```

```json
{
  "api": "https://api.sb/ratebook.dev",
  "dataset": {
    "$id": "https://api.sb/ratebook.dev/datasets/dataset_UDQXk0KsJB",
    "$type": "Dataset",
    "name": "Ratebook",
    "promise": "A rate for any US address in under 100 milliseconds.",
    "status": "draft"
  },
  "action": {
    "$id": "https://api.sb/ratebook.dev/actions/act_M5LgINdysq",
    "operation": "Dataset.refresh",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/ratebook.dev/actions/act_M5LgINdysq"
  }
}
```