# Create Schedule

`POST /analytics/{datasetSlug}/schedules` · Core · Analytics & Intelligence

Creates a recurring materialization from a collection into this dataset. Body: `fromCollection`, `intervalSeconds` (at least 60) and optional `reattestIntervalDays` (7, 30, 90 or 365). Each run reads the collection with its creator's current access. The schedule keeps running only while it is re-attested within the interval.

Requires the `datasets:write` permission (PROJECT_ADMIN or PROJECT_AUTHOR by default).

Callers must be members of the project (an organization role alone does not grant access); project service tokens and extension tokens cannot call it.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `datasetSlug` | path | yes | The Dataset's slug. Example: `"orders"`. |
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `fromCollection` | string | yes | The collection each run snapshots into the dataset: letters, digits and underscores, not starting with a digit. Each run reads it as the person who created the schedule, so it writes only the rows they can see. |
| `intervalSeconds` | integer | yes | Seconds between runs. At least 60. The first run is due as soon as the schedule is created. |
| `reattestIntervalDays` | object | no | How many days each attestation lasts: 7, 30, 90 or 365. Default 90. When it runs out, the schedule stops running until someone re-attests it. |
| _one of_ | | |  |
| _or_ | | |  |
| _or_ | | |  |
| _or_ | | |  |

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | A materialization schedule: a collection snapshotted into the dataset at a fixed interval. |
| `data.id` | string | yes | The schedule's id (`msch_...`). |
| `data.datasetSlug` | string | yes | The dataset each run writes to. |
| `data.sourceCollection` | string | yes | The collection each run snapshots. |
| `data.intervalSeconds` | integer | yes | Seconds between runs. |
| `data.enabled` | boolean | yes | Whether the schedule is set to run. |
| `data.reattestIntervalDays` | integer | yes | How many days each attestation lasts: 7, 30, 90 or 365. |
| `data.attestedAt` | string (date-time) | yes | When a person last confirmed the schedule (created or re-attested it). |
| `data.expiresAt` | string (date-time) | yes | `attestedAt` plus `reattestIntervalDays`. After it the schedule stops running until it is re-attested; it isn't deleted. |
| `data.attestationStatus` | enum ("active", "expiring_soon", "expired") | yes | `expiring_soon` within 14 days of `expiresAt`. |
| `data.lastRunAt` | object | yes | When the schedule last ran. Null if it has never run. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.lastRunStatus` | object | yes | How the last run ended: `ok`, `error`, `stale_principal_denied` (the person who configured it has lost write access to the dataset) or `attestation_expired`. Null if it has never run. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.nextRunAt` | string (date-time) | yes | When the schedule is next due. |
| `data.createdAt` | string (date-time) | yes | When the schedule was created. |
| `meta` | object | yes | Request metadata: cost, timing and correlation ids. |
| `meta.cost` | object | yes | Metered usage for this request; empty when nothing was metered. |
| `meta.timing` | object | yes |  |
| `meta.timing.gatewayMs` | number | yes |  |
| `meta.timing.totalMs` | number | yes |  |
| `meta.context` | object | yes |  |
| `meta.context.requestId` | string | yes |  |
| `meta.context.traceId` | string | yes |  |
| `meta.context.projectId` | string | no |  |
| `meta.warnings` | array of object | no |  |
| `meta.warnings.[]code` | string | yes |  |
| `meta.warnings.[]message` | string | yes |  |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_UNAUTHENTICATED` | The caller is not signed in. |
| 403 | `K9O_ACCESS_DENIED` | The caller is not a member of this project; an organization role alone does not grant access. |
| 404 | `K9O_NOT_FOUND` | The project was not found for this caller (project service tokens and extension tokens cannot call this endpoint). |
| 403 | `K9O_IAM_POLICY_DENIED` | The caller's role or IAM policy does not grant datasets:write. |
| 400 | `K9O_INVALID_REQUEST_SHAPE` | The request body does not match the schema. |
| 400 | `K9O_INVALID_FIELD_VALUE` | `fromCollection`, `intervalSeconds` or `reattestIntervalDays` is invalid. |
| 404 | `K9O_DATASET_NOT_FOUND` | No active dataset with this slug exists in the project. |
| 409 | `K9O_PENDING_CHANGE_ALREADY_EXISTS` | A schedule for this dataset and collection already exists. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/analytics/<datasetSlug>/schedules' \
  -H 'Authorization: Bearer $K9O_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/analytics/<datasetSlug>/schedules', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({}),
});
const { data, meta } = await res.json();
```

### k9o CLI

```bash
k9o analytics schedules create <dataset> --from-collection <name> --interval-seconds N
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.analytics.schedules.create('<datasetSlug>', {})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.analytics.schedules.create("<datasetSlug>", {})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Analytics.Schedules.Create(ctx, "<datasetSlug>", map[string]any{})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.analytics.schedules.create("<datasetSlug>", json!({})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.analytics().schedules().create("<datasetSlug>", Map.of())
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Analytics.Schedules.CreateAsync("<datasetSlug>", new Dictionary<string, object> {  })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.analytics.schedules.create("<datasetSlug>", {  })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->analytics->schedules->create('<datasetSlug>', [])
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/create-schedule
