# Filter Metadata

`POST /metadata/query` · Core · Data, Queries & Vectors

Create query. (Data, Queries & Vectors) POST `/@:projectSlug/metadata/query`.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `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 |
|---|---|---|---|
| `surfaces` | array of string | yes | The surfaces to read, at least one. A `storage:` surface answers 501. Together they may return at most 10,000 rows (413 above that). |
| `where` | array of object | no | Filters; every clause must match. On a collection surface, one clause per field. |
| `where.[]field` | string | yes | The field to filter on. On a collection surface, `metadata.<column>` for a declared column. On a telemetry surface, `createdAt` (with `gt`, `gte`, `lt`, `lte`) or `actorId` (with `eq`). |
| `where.[]op` | enum ("eq", "neq", "gt", "gte", "lt", "lte", "contains", "startsWith", "endsWith", "in", "notIn", "and", "or", "not") | yes | The operator. `and`, `or` and `not` are accepted by the parser but refused by every surface. A protected (encrypted) column allows only `eq` with a non-null value, and `in`. |
| `where.[]value` | object | yes | The value to compare with. `in` and `notIn` take a non-empty array of strings, numbers or booleans (none containing `,`, `(` or `)`). `eq` and `neq` with null test for null. Other operators take one string, number or boolean. |
| _one of_ | | |  |
| _or_ | | |  |
| _or_ | | |  |
| _or_ | | |  |
| _or_ | | |  |
| _one of_ | | |  |
| _or_ | | |  |
| _or_ | | |  |
| `limit` | integer | no | Rows per surface. Default 100. A telemetry surface returns at most 200. |
| `cursor` | object | no | `meta.cursor.next` from the previous page. Only with a single surface. |
| _one of_ | | |  |
| _or_ | | |  |

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | array of object | yes | The matching rows. A query over several surfaces lists each surface's rows in the order the surfaces were named. |
| `data.[]surface` | string | yes | The surface label the row came from, as sent. |
| `data.[]scope` | string | yes | The surface's scope: the collection name, or the audit event type for telemetry. |
| `data.[]recordId` | string | no | The record's id. Present on collection rows only. |
| `data.[]eventId` | string | no | The audit event's id. Present on telemetry rows only. |
| `data.[]metadata` | object | yes | For a collection surface: the record's declared metadata columns (see PUT /metadata/index/{collection}), keyed by column name, with each value as the record read returns it (string, number, boolean, null, or an array or object for array and jsonb columns). A declared column the record read did not return is absent. For a telemetry surface: the audit event as GET /audit-log returns it. |
| `meta` | object | yes | Request metadata (request id, trace id, timing and cost) plus `cursor.next`: pass it as `cursor` to read the next page, or null when there is no next page. |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_INVALID_CREDENTIALS` | The caller is not authenticated. |
| 403 | `K9O_ACCESS_DENIED` | The caller has no read access to the collection (the record read's own gate). |
| 403 | `K9O_EXTENSION_PERMISSION_DENIED` | An extension token: the Metadata API is not extension-callable yet. |
| 400 | `K9O_INVALID_FIELD_VALUE` | The body is malformed: an unknown field, a wrong type, or an unsupported where operator. |
| 400 | `K9O_UNKNOWN_SURFACE` | A surface is not collection:<name>, storage:<bucket> or telemetry:<eventType>. |
| 400 | `K9O_METADATA_FIELD_NOT_INDEXED` | A field is not a declared metadata field of the surface (ch04 §1.3.1); declare it with PUT /metadata/index/{collection}. |
| 400 | `K9O_INVALID_FILTER` | A where value is invalid for the column. |
| 413 | `K9O_QUERY_RESULT_TOO_LARGE` | The union of the surfaces' rows exceeds the cross-surface cap. |
| 501 | `K9O_NOT_IMPLEMENTED` | The storage slice is not available yet (object metadata has no query index). |

## Code samples

### cURL

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

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/metadata/query', {
  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 metadata filter --surface <s1[,s2,...]>
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.metadata.filter({})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.metadata.filter({})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Metadata.Filter(ctx, 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.metadata.filter(json!({})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.metadata().filter(Map.of())
```

### K9o.Core

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

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.metadata.filter({  })
```

### k9o/sdk

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


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/filter-metadata
