# Posts

> Publish text and media posts from a connected account, read stats, and delete.

Publish content from a connected account, attach images or video, read a post's engagement stats, and delete.

## Upload media (optional)

To attach a photo or video, upload it first and use the returned `media_id` when creating the post.

```http
POST /v1/media
```

Send the file as `multipart/form-data` with fields `account_id`, `kind` (`image` or `video`) and `file`.

```bash
curl -X POST https://api.correctinbox.com/v1/media \
  -H "X-API-KEY: $CORRECTINBOX_API_KEY" \
  -F account_id=acc_8f21c0 \
  -F kind=image \
  -F file=@./launch.png
```

```js
const form = new FormData();
form.append("account_id", "acc_8f21c0");
form.append("kind", "image");
form.append("file", fileBlob, "launch.png");
const { media_id } = await (
  await fetch("https://api.correctinbox.com/v1/media", {
    method: "POST",
    headers: { "X-API-KEY": process.env.CORRECTINBOX_API_KEY },
    body: form,
  })
).json();
```

```python
media_id = requests.post(
    "https://api.correctinbox.com/v1/media",
    headers={"X-API-KEY": os.environ["CORRECTINBOX_API_KEY"]},
    data={"account_id": "acc_8f21c0", "kind": "image"},
    files={"file": open("launch.png", "rb")},
).json()["media_id"]
```

## Create a post

```http
POST /v1/posts
```

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `account_id` | string | yes | The publishing account. |
| `text` | string | yes | The post body. |
| `media` | array | no | Media objects: `{ "media_id": "...", "alt": "..." }`. |
| `visibility` | string | no | `anyone` (default) or `connections`. |

```bash
curl -X POST https://api.correctinbox.com/v1/posts \
  -H "X-API-KEY: $CORRECTINBOX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "acc_8f21c0",
    "text": "We just shipped something we are proud of.",
    "media": [{ "media_id": "med_3a9", "alt": "Product screenshot" }]
  }'
```

```js
const post = await (
  await fetch("https://api.correctinbox.com/v1/posts", {
    method: "POST",
    headers: {
      "X-API-KEY": process.env.CORRECTINBOX_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      account_id: "acc_8f21c0",
      text: "We just shipped something we are proud of.",
      media: [{ media_id: "med_3a9", alt: "Product screenshot" }],
    }),
  })
).json();
```

```python
post = requests.post(
    "https://api.correctinbox.com/v1/posts",
    headers={"X-API-KEY": os.environ["CORRECTINBOX_API_KEY"]},
    json={
        "account_id": "acc_8f21c0",
        "text": "We just shipped something we are proud of.",
        "media": [{"media_id": "med_3a9", "alt": "Product screenshot"}],
    },
).json()
```

**Response**

```json
{ "object": "post", "id": "pst_91f", "account_id": "acc_8f21c0", "url": "https://www.linkedin.com/feed/update/urn:li:activity:7160..." }
```

## Post stats

```http
GET /v1/posts/{post_id}/stats?account_id={account_id}
```

```json
{ "likes": 42, "comments": 7, "reposts": 3 }
```

## Delete a post

```http
DELETE /v1/posts/{post_id}?account_id={account_id}
```

```bash
curl -X DELETE "https://api.correctinbox.com/v1/posts/pst_91f?account_id=acc_8f21c0" \
  -H "X-API-KEY: $CORRECTINBOX_API_KEY"
```
