# Upload File

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

Uploads a CSV or JSON file (raw body, or multipart with `file` and an optional `manifest`), up to 25 MiB. Query: `format` (`csv` or `json`, required), `dryRun`, `onError`, and for CSV `delimiter`, `encoding` and `hasHeader`. `dryRun` returns the detected columns and a 50-row preview without writing. A `manifest` on a slug that does not exist yet creates the dataset and loads the file in one call. Returns the ingest counts; the original file is kept for download.

Requires the `datasets:write` permission (PROJECT_ADMIN or PROJECT_AUTHOR by default). A dry run or a manifest create needs `datasets:create`.

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"`. |
| `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 |
|---|---|---|---|
| `file` | string (binary) | yes | The CSV or JSON file (`?format=csv\|json`), at most 25 MiB. |
| `manifest` | string | no | JSON: creates the dataset from this definition, then ingests the file. Omit it to append to an existing dataset. |

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | `?dryRun=true`: the inferred schema and a sample; otherwise the ingest result. |
| _one of_ | | |  |
| `data.dryRun` | enum (true) | yes | Always true: nothing was written. |
| `data.detected` | object | yes | How the file was read. |
| `data.detected.encoding` | enum ("utf-8", "utf-8-bom", "latin-1", "windows-1252") | yes | The file's text encoding: detected, or the `encoding` you sent. |
| `data.detected.delimiter` | enum (",", ";", "\t") | no | The CSV field delimiter: detected from the header line, or the `delimiter` you sent. Absent for JSON. |
| `data.detected.format` | enum ("csv", "json") | yes | The file format, from `?format=`. |
| `data.columns` | array of object | yes | The proposed columns, in file order. Review them, then create the dataset with them (or send them as the `manifest`). |
| `data.columns.[]sourceName` | string | yes | The column's name in the file: the CSV header cell, `col_1`, `col_2`, ... when `hasHeader=false`, or the JSON key. |
| `data.columns.[]name` | string | yes | The proposed column name: `sourceName` trimmed and lowercased, with each run of characters other than letters and digits turned into one `_`. |
| `data.columns.[]type` | string | yes | The proposed column type: the narrowest type every non-empty sampled value fits, or `string`. |
| `data.columns.[]nullable` | boolean | yes | True when any sampled value was empty or null. |
| `data.columns.[]nullCount` | integer | yes | How many sampled values were empty or null. |
| `data.columns.[]typedCandidate` | object | yes | The narrowest non-string type that most values fit. Equal to `type` when the column fits it cleanly; when `type` is `string` because a few values don't fit, this names the type they broke. Null when no non-string type fits. |
| _one of_ | | |  |
| _or_ | | |  |
| `data.columns.[]typedCandidateMismatches` | integer | yes | How many non-empty values don't fit `typedCandidate`: the rows that would be skipped if you declared it. 0 when the column fits cleanly. |
| `data.sampledRows` | integer | yes | How many rows the proposal was inferred from. |
| `data.sample` | array of object | yes | The first rows of the file as parsed, at most 50. |
| _or_ | | |  |
| `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. |
| `data.provenance` | object | no | The stored original, when the provenance store is available. |
| `data.provenance.uploadId` | string | yes | The stored original's id (`prov_...`). |
| `data.provenance.filename` | string | yes | The file name stored with it: the uploaded file's name, or `upload.csv` / `upload.json` when it had none. |
| `data.provenance.byteSize` | integer | yes | The original file's size in bytes. |
| `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 file cannot be parsed, exceeds 25 MiB, or a query parameter or the manifest is invalid. |
| 400 | `K9O_INGEST_SCHEMA_MISMATCH` | A row does not match the dataset's schema and `onError=reject`. |
| 400 | `K9O_DATASET_INVALID` | The manifest is invalid, or the dataset already exists. |
| 400 | `K9O_DATASET_STORAGE_TARGET_INVALID` | The manifest's storage location does not exist or is retired. |
| 429 | `K9O_DATASET_LIMIT_EXCEEDED` | The project already has the maximum number of datasets (200). |
| 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>/upload' \
  -H 'Authorization: Bearer $K9O_TOKEN'
```

### fetch

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

### k9o CLI

```bash
k9o analytics upload <slug> <file>
```

### @k9o/core

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

### k9o

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

### sdk-go

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

### k9o

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

### dev.k9o:core

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

### K9o.Core

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

### k9o

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

### k9o/sdk

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


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/upload-file
