# Write Dataset Rows

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

Appends rows: the body is newline-delimited JSON or a JSON array. Each row is validated against the dataset's schema; `onError=skip` (default) skips bad rows and reports them, `onError=reject` refuses the whole write (`400 K9O_INGEST_SCHEMA_MISMATCH`). Returns `ingested`, `skipped`, up to 100 `skippedDetails`, the partitions touched and the bytes written. Platform telemetry datasets cannot be written.

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.

Returns `503 K9O_ANALYTICS_UNAVAILABLE` until the region's analytics storage is provisioned.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `datasetSlug` | path | yes | The Dataset's slug. Example: `"orders"`. |
| `onError` | query | no | What a row that doesn't conform does: `skip` (the default) writes the other rows and reports it in `skippedDetails`; `reject` refuses the whole write, so nothing is written. Example: `"skip"`. |
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | The result of the write: how many rows were written and skipped, and why. |
| `data.ingested` | integer | yes | Rows written to the dataset. |
| `data.skipped` | integer | yes | Rows not written: rows that don't match the dataset's declared columns, plus rows the dataset write refused. |
| `data.skippedDetails` | array of object | yes | The skipped rows and why, at most 100. Empty when nothing was skipped. |
| `data.skippedDetails.[]index` | integer | yes | The skipped row's position, counting from 0. |
| `data.skippedDetails.[]reason` | string | yes | Why the row was skipped, in plain text. |
| `data.partitionsTouched` | array of string | yes | The partition paths written, region first, such as `region=eu/occurred_at=2026-11-02`. Empty when nothing was written. |
| `data.bytes` | integer | yes | Request body size. |
| `data.bytesWritten` | integer | no | Present when anything was written. |
| `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_INGEST_PARSE_FAILED` | The body is empty or not valid NDJSON / JSON, or `onError` is invalid. |
| 400 | `K9O_INGEST_SCHEMA_MISMATCH` | A row does not match the dataset's schema and `onError=reject`. |
| 404 | `K9O_DATASET_NOT_FOUND` | No active dataset with this slug exists in the project. |
| 403 | `K9O_FORBIDDEN` | Platform telemetry datasets are read-only. |
| 503 | `K9O_ANALYTICS_UNAVAILABLE` | The region's analytics storage is not available yet; retry later. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/analytics/<datasetSlug>/write' \
  -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>/write', {
  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 write <slug> --rows <json> --rows-file <path|->
```

### @k9o/core

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

### k9o

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

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Analytics.Write(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.write("<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().write("<datasetSlug>", Map.of())
```

### K9o.Core

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

### k9o

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

### k9o/sdk

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


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/write-dataset-rows
