# Create or update a post

> For AI agents: the index of these docs is at https://indrava.forumulate.com/docs/llms.txt (every page it lists has a Markdown version like this one).

## Create or update a post

**`POST http://localhost:4000/api/v1/posts`** — Create or update a post

`action` decides what happens: `draft` saves, `schedule` publishes at `scheduledAt`, `now` publishes right away (both need the `posts:publish` scope). Send `id` to update a draft or scheduled post. When creating, send `idempotencyKey` to make a retry safe: the same key returns the first post. A part may name files by address in `mediaUrls`: each is added to the media library first (needs `media:write`; an address named twice in one call is fetched once). Scheduling the same text and files to a channel that already has them within 24 hours answers 409 with `existingPostId`; send `allowDuplicate: true` to schedule it anyway. A workspace's own rules (banned words, required tags) refuse scheduling with 400. For keys and tokens the answer carries `previewUrl`, a view-only link to the post as it will publish.

### Request body (`application/json`)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | no |  |
| `parts` | object[] | yes |  |
| `parts.text` | string | yes |  |
| `parts.mediaIds` | string[] | no | Default: `[]`. |
| `parts.delaySeconds` | integer | no |  |
| `parts.mediaUrls` | string[] | no |  |
| `targets` | object[] | yes |  |
| `targets.channelId` | string | yes |  |
| `targets.parts` | object[] | no |  |
| `targets.parts.text` | string | yes |  |
| `targets.parts.mediaIds` | string[] | no | Default: `[]`. |
| `targets.parts.delaySeconds` | integer | no |  |
| `targets.parts.mediaUrls` | string[] | no |  |
| `targets.settings` | object | no | Default: `{}`. |
| `action` | string | yes | One of: `draft` \| `schedule` \| `now`. |
| `scheduledAt` | string | no |  |
| `tagIds` | string[] | no |  |
| `clientId` | string | no |  |
| `aiGenerated` | boolean | no |  |
| `idempotencyKey` | string | no |  |
| `allowDuplicate` | boolean | no |  |

```json
{
  "id": "string",
  "parts": [
    {
      "text": "string",
      "mediaIds": [],
      "delaySeconds": 0,
      "mediaUrls": [
        "string"
      ]
    }
  ],
  "targets": [
    {
      "channelId": "string",
      "parts": [
        {
          "text": "string",
          "mediaIds": [],
          "delaySeconds": 0,
          "mediaUrls": [
            "string"
          ]
        }
      ],
      "settings": {}
    }
  ],
  "action": "draft",
  "scheduledAt": "2024-01-01T00:00:00Z",
  "tagIds": [
    "string"
  ],
  "clientId": "string",
  "aiGenerated": true,
  "idempotencyKey": "string",
  "allowDuplicate": true
}
```

### Responses

**200** — OK

#### Fields

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes |  |
| `previewUrl` | string | no |  |

```json
{
  "id": "string",
  "previewUrl": "string"
}
```

### Code samples

**cURL**

```curl
curl -X POST "http://localhost:4000/api/v1/posts" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"id":"string","parts":[{"text":"string","mediaIds":[],"delaySeconds":0,"mediaUrls":["string"]}],"targets":[{"channelId":"string","parts":[{"text":"string","mediaIds":[],"delaySeconds":0,"mediaUrls":["string"]}],"settings":{}}],"action":"draft","scheduledAt":"2024-01-01T00:00:00Z","tagIds":["string"],"clientId":"string","aiGenerated":true,"idempotencyKey":"string","allowDuplicate":true}'
```

**TypeScript**

```typescript
const res = await fetch('http://localhost:4000/api/v1/posts', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer $API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"id":"string","parts":[{"text":"string","mediaIds":[],"delaySeconds":0,"mediaUrls":["string"]}],"targets":[{"channelId":"string","parts":[{"text":"string","mediaIds":[],"delaySeconds":0,"mediaUrls":["string"]}],"settings":{}}],"action":"draft","scheduledAt":"2024-01-01T00:00:00Z","tagIds":["string"],"clientId":"string","aiGenerated":true,"idempotencyKey":"string","allowDuplicate":true}),
});
const data = await res.json();
```

**Python**

```python
import requests

res = requests.request(
    "POST",
    "http://localhost:4000/api/v1/posts",
    headers={
    "Authorization": "Bearer $API_KEY",
    "Content-Type": "application/json",
    },
    json={"id": "string", "parts": [{"text": "string", "mediaIds": [], "delaySeconds": 0, "mediaUrls": ["string"]}], "targets": [{"channelId": "string", "parts": [{"text": "string", "mediaIds": [], "delaySeconds": 0, "mediaUrls": ["string"]}], "settings": {}}], "action": "draft", "scheduledAt": "2024-01-01T00:00:00Z", "tagIds": ["string"], "clientId": "string", "aiGenerated": True, "idempotencyKey": "string", "allowDuplicate": True},
)
data = res.json()
```

**Go**

```go
package main

import (
	"fmt"
	"io"
	"net/http"
	"strings"
)

func main() {
	req, _ := http.NewRequest("POST", "http://localhost:4000/api/v1/posts", strings.NewReader(`{"id":"string","parts":[{"text":"string","mediaIds":[],"delaySeconds":0,"mediaUrls":["string"]}],"targets":[{"channelId":"string","parts":[{"text":"string","mediaIds":[],"delaySeconds":0,"mediaUrls":["string"]}],"settings":{}}],"action":"draft","scheduledAt":"2024-01-01T00:00:00Z","tagIds":["string"],"clientId":"string","aiGenerated":true,"idempotencyKey":"string","allowDuplicate":true}`))
	req.Header.Set("Authorization", "Bearer $API_KEY")
	req.Header.Set("Content-Type", "application/json")
	res, _ := http.DefaultClient.Do(req)
	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)
	fmt.Println(string(body))
}
```

**PHP**

```php
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:4000/api/v1/posts');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer $API_KEY', 'Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"id":"string","parts":[{"text":"string","mediaIds":[],"delaySeconds":0,"mediaUrls":["string"]}],"targets":[{"channelId":"string","parts":[{"text":"string","mediaIds":[],"delaySeconds":0,"mediaUrls":["string"]}],"settings":{}}],"action":"draft","scheduledAt":"2024-01-01T00:00:00Z","tagIds":["string"],"clientId":"string","aiGenerated":true,"idempotencyKey":"string","allowDuplicate":true}');
$response = curl_exec($ch);
curl_close($ch);
echo $response;
```

**Ruby**

```ruby
require 'net/http'
require 'uri'

uri = URI('http://localhost:4000/api/v1/posts')
req = Net::HTTP::Post.new(uri)
req['Authorization'] = 'Bearer $API_KEY'
req['Content-Type'] = 'application/json'
req.body = '{"id":"string","parts":[{"text":"string","mediaIds":[],"delaySeconds":0,"mediaUrls":["string"]}],"targets":[{"channelId":"string","parts":[{"text":"string","mediaIds":[],"delaySeconds":0,"mediaUrls":["string"]}],"settings":{}}],"action":"draft","scheduledAt":"2024-01-01T00:00:00Z","tagIds":["string"],"clientId":"string","aiGenerated":true,"idempotencyKey":"string","allowDuplicate":true}'
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
  http.request(req)
end
puts res.body
```

**Java**

```java
import java.net.URI;
import java.net.http.*;
import java.net.http.HttpRequest.BodyPublishers;

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("http://localhost:4000/api/v1/posts"))
    .header("Authorization", "Bearer $API_KEY")
    .header("Content-Type", "application/json")
    .method("POST", BodyPublishers.ofString("{\"id\":\"string\",\"parts\":[{\"text\":\"string\",\"mediaIds\":[],\"delaySeconds\":0,\"mediaUrls\":[\"string\"]}],\"targets\":[{\"channelId\":\"string\",\"parts\":[{\"text\":\"string\",\"mediaIds\":[],\"delaySeconds\":0,\"mediaUrls\":[\"string\"]}],\"settings\":{}}],\"action\":\"draft\",\"scheduledAt\":\"2024-01-01T00:00:00Z\",\"tagIds\":[\"string\"],\"clientId\":\"string\",\"aiGenerated\":true,\"idempotencyKey\":\"string\",\"allowDuplicate\":true}"))
    .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

---

## For AI agents

- This page for a human reader: https://indrava.forumulate.com/docs/ref-posts-save
- The whole space as one Markdown file: https://indrava.forumulate.com/docs/llms-full.txt
- Live search + fetch over MCP: https://indrava.forumulate.com/docs/_api/public/orgs/e421ace4-3e78-4ed8-9818-7b4899cf3aa0/spaces/2bcc7f09-4489-40af-85d8-9fdd3f3da314/mcp
  - Install (Claude CLI): `claude mcp add forumulate-docs --transport http https://indrava.forumulate.com/docs/_api/public/orgs/e421ace4-3e78-4ed8-9818-7b4899cf3aa0/spaces/2bcc7f09-4489-40af-85d8-9fdd3f3da314/mcp`

This Markdown is the same content the page renders — safe to quote and to ground answers in.
