# Publish to Stream

`POST /data-streams/user/{streamSlug}/publish` · Core · Realtime Feeds & Streams

Appends one message to a user stream. `data` is any JSON value; the optional `subject` is a routing suffix under the stream's `subjectPrefix`, so a publish never leaves the stream's own namespace. Answers 202 once the broker has stored the message, with the full subject and the payload size. Needs PROJECT_ADMIN.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `streamSlug` | path | yes | The stream's slug, unique in the project. Example: `"order-events"`. |
| `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 |
|---|---|---|---|
| `data` | object | yes | The event payload: any JSON value (object, array, string, number, boolean or null). It is stored as JSON and delivered to consumers unchanged. |
| `subject` | string | no | An optional routing suffix appended under the stream's `subjectPrefix`: up to 8 dot-separated segments, each 1 to 64 characters of `a-z`, `0-9`, `_` or `-` (no wildcards). Omitted, the message is published on `<subjectPrefix>._`. |

## Responses

- **202**: Accepted

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | The message was stored on the stream. |
| `data.streamSlug` | string | yes | The stream the message was published to. |
| `data.subject` | string | yes | The full subject the message was published on. |
| `data.bytes` | integer | yes | The size of the stored payload: the UTF-8 bytes of `data` serialized as JSON. |
| `data.accepted` | enum (true) | yes | Always true: the broker acknowledged the message. |
| `meta` | object | yes |  |


## Errors

| HTTP | Code | When |
|---|---|---|
| 503 | `K9O_STREAM_UNAVAILABLE` | Pulse Stream messaging is not configured in this deployment, or the project's stream account is not provisioned, so the message was not stored. Retry later. |
| 403 | `K9O_RBAC_DENY` | Publishing to a Pulse Stream requires PROJECT_ADMIN (or org-cascade). |
| 404 | `K9O_STREAM_NOT_FOUND` | No active Pulse Stream with that slug in this project. |
| 400 | `K9O_STREAM_INVALID` | The publish subject is malformed (too many segments, or an invalid segment). |

## Code samples

### cURL

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

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/data-streams/user/<streamSlug>/publish', {
  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 stream publish <slug> --data <json|@file|->
```

### @k9o/core

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

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.streams.publish("<streamSlug>", {})
```

### sdk-go

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

### dev.k9o:core

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

### K9o.Core

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

### k9o

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

### k9o/sdk

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

### K9o

```swift
// let k9o = try K9o.createClient(orgSlug: "playground", projectSlug: "storefront", apiKey: "k9o_…")
let result = try await k9o.streams.publish("<streamSlug>", {})
```

### core-kotlin

```kotlin
// val k9o = createClient { orgSlug = "playground"; projectSlug = "storefront"; apiKey = "k9o_…" }
val result = k9o.streams.publish("<streamSlug>", {})
```

### k9o (Flutter)

```dart
// final k9o = K9o.createClient(orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…');
final result = await k9o.streams.publish('<streamSlug>', {})
```

### @k9o/react-native

```javascript
// const k9o = createClient({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })  // RN, secure storage
const { data } = await k9o.streams.publish('<streamSlug>', {})
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/publish-to-stream
