# Search Metadata

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

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

## 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 |
|---|---|---|---|
| `surface` | string | yes | A surface label `<slice>:<scope>`: `collection:<name>`, `telemetry:<eventType>` or `storage:<bucket>`. The scope is 1 to 128 characters of letters, digits, `.`, `_`, `:` and `-`, starting with a letter or digit. Only a collection surface is accepted here. |
| `field` | string | yes | The declared text column to search, as `metadata.<column>`. Not a protected column. |
| `q` | string | yes | The full-text search terms. |
| `limit` | integer | no | How many rows to return, as the record read's `limit`. |

## 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}. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/metadata/search' \
  -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/search', {
  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 search --surface <collection:name> --field <column> --q <text>
```

### @k9o/core

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

### k9o

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

### sdk-go

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

### dev.k9o:core

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

### K9o.Core

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

### k9o

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

### k9o/sdk

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


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