# Social publishing API

> Schedule Facebook, Instagram and YouTube posts from your own app, CMS or automation tool.

_Source: https://hexafloww.com/docs/account/social-publishing-api_

---

The social publishing API lets another platform - your CMS, an internal tool, Zapier, Make or n8n - schedule and publish **Facebook Page** and **Instagram** posts, and **YouTube** videos, through HexaFloww. Posts created through the API show up in the **Scheduler** with an **API** tag, and HexaFloww publishes them on time, exactly like posts made in the app.

You also get **webhooks**: HexaFloww calls your URL when a post goes live, fails, or an account needs reconnecting, so you don't have to keep checking.

> [!NOTE]
> Requires a plan with full social features. Connect your Facebook Page / Instagram account in **Connect Accounts → Meta**, or your YouTube channel in **Connect Accounts → YouTube**, first - the API can only post to accounts that are already connected.

## 1. Create an API key

On **Settings → API Keys**, generate a key with the `social:read` and `social:write` permissions (add `social:engage` if you'll use first comments, auto-replies or reply to comments). Send it on every request:

```
Authorization: Bearer hxg_...
```

All requests and responses are JSON. Base URL: `https://hexafloww.com/api/v1/social`.

## 2. Find your account ids

```
GET /api/v1/social/accounts
```

```json
{ "data": [
  { "id": 41, "platform": "facebook", "name": "Acme Store", "status": "active",
    "reconnectBy": "2027-01-20T00:00:00.000Z", "canPublish": true, "reason": null },
  { "id": 42, "platform": "instagram", "name": "acmestore", "status": "active",
    "reconnectBy": null, "canPublish": true, "reason": null },
  { "id": 43, "platform": "youtube", "name": "Acme TV", "status": "active",
    "reconnectBy": null, "canPublish": true, "reason": null }
]}
```

If `canPublish` is `false`, `reason` explains what to fix (usually: reconnect the account in HexaFloww).

## 3. Upload media

Meta and YouTube receive post media when it publishes, so media must be hosted by HexaFloww. Upload a file, or give us a public `https://` URL to copy:

```
POST /api/v1/social/media
Content-Type: multipart/form-data   (field: file)
```

```
POST /api/v1/social/media
Content-Type: application/json

{ "url": "https://cdn.example.com/autumn.jpg" }
```

```json
{ "data": { "url": "https://hexafloww.com/uploads/social-posts/project_7/3f1c….jpg",
            "type": "image", "mime": "image/jpeg", "bytes": 482113 } }
```

Images: JPG, PNG, GIF, WEBP up to 10 MB (use **JPG for Instagram**). Video: MP4 or MOV up to 200 MB. Limit: 30 uploads per minute.

## 4. Create a post

```
POST /api/v1/social/posts
Idempotency-Key: cms-post-8812-v1
```

```json
{
  "accountIds": [41, 42],
  "content": "Our autumn collection is live 🍂",
  "media": [
    { "url": "https://hexafloww.com/uploads/social-posts/project_7/a.jpg", "type": "image" },
    { "url": "https://hexafloww.com/uploads/social-posts/project_7/b.jpg", "type": "image" }
  ],
  "scheduledAt": "2026-11-10T18:30:00+05:30",
  "externalId": "cms-post-8812",
  "metadata": { "campaign": "autumn" },
  "overrides": {
    "instagram": { "content": "Autumn is here 🍂 #acme #fall #newcollection" }
  }
}
```

**Same caption everywhere, or customised per platform** - just like "Customise post for Facebook and Instagram" in the app. Leave `overrides` out and every account gets `content`. Add an `overrides` entry to give a platform its own caption (and, if you like, its own `media` or `coverUrl`). Keys can be a platform (`"facebook"`, `"instagram"`, `"youtube"`) or a specific account id; an account-id entry beats its platform entry.

One post is created per account. The response (`201`) lists them, plus any non-blocking `warnings`:

```json
{ "data": [
  { "id": 9001, "accountId": 41, "platform": "facebook", "status": "scheduled",
    "content": "Our autumn collection is live 🍂", "customized": false,
    "scheduledAt": "2026-11-10T13:00:00.000Z", "groupId": "grp_…", "externalId": "cms-post-8812", … },
  { "id": 9002, "accountId": 42, "platform": "instagram", "status": "scheduled",
    "content": "Autumn is here 🍂 #acme #fall #newcollection", "customized": true, … }
], "warnings": [] }
```

| Field | Notes |
| --- | --- |
| `accountIds` | Required. 1-10 ids from step 2. |
| `content` | Caption / text. Instagram: max 2,200 characters and 30 hashtags. |
| `media` | URLs from step 3. 1 image, 2-10 images (carousel / multi-photo), or 1 video. No mixing images and video. Instagram always needs media. |
| `coverUrl` | Optional thumbnail image for a video post. |
| `placement` | `feed` (default) or `story`. Each media item becomes one story frame (up to 20). |
| `scheduledAt` | ISO 8601 **with a timezone** (`Z` or `+05:30`), at least 1 minute ahead and at most 365 days. |
| `publishNow` | `true` publishes within seconds instead of scheduling. Don't send it together with `scheduledAt`. |
| neither | The post is saved as a **draft**. |
| `externalId` | Your own id for the post; you can filter by it later. |
| `metadata` | Any JSON object (max 4 KB), sent back to you in webhooks. |
| `youtube` | YouTube video settings - see **YouTube videos** below. Required when posting to a YouTube channel. |
| `overrides` | Customise `content`, `media`, `coverUrl` (or `youtube`) per platform (`"facebook"` / `"instagram"` / `"youtube"`) or per account id. Anything not overridden uses the shared value. |

### YouTube videos

Include a YouTube channel id in `accountIds` and add a `youtube` object. `content` becomes the video **description**, and `media` must be exactly **one video**. `coverUrl` is used as the custom thumbnail (JPG or PNG, max 2 MB, 1280x720 recommended; YouTube only allows custom thumbnails on verified channels). If the thumbnail or playlist step is refused, the video still publishes and the reason is listed in `youtube.warnings`.

```json
{
  "accountIds": [41, 43],
  "content": "Behind the scenes of our autumn shoot.",
  "media": [{ "url": "https://hexafloww.com/uploads/social-posts/project_7/shoot.mp4", "type": "video" }],
  "scheduledAt": "2026-11-10T18:30:00+05:30",
  "youtube": {
    "title": "Autumn collection - behind the scenes",
    "privacy": "public",
    "tags": ["fashion", "autumn", "behind the scenes"],
    "categoryId": "26",
    "madeForKids": false,
    "notifySubscribers": true
  },
  "overrides": {
    "youtube": { "content": "Full behind-the-scenes video of our autumn shoot. Shop the collection in our store." }
  }
}
```

| `youtube` field | Notes |
| --- | --- |
| `title` | **Required** for YouTube. Max 100 characters, no `<` or `>`. |
| `privacy` | `public` (default), `unlisted` or `private`. |
| `tags` | Array of strings, max 500 characters in total. |
| `categoryId` | YouTube category id (default `22`, People & Blogs). Common ones: `1` Film & Animation, `10` Music, `17` Sports, `20` Gaming, `22` People & Blogs, `23` Comedy, `24` Entertainment, `25` News & Politics, `26` Howto & Style, `27` Education, `28` Science & Technology. |
| `madeForKids` | `true` if the video is made for children (YouTube requires you to declare this). Default `false`. |
| `notifySubscribers` | Default `true`. |
| `containsSyntheticMedia` | `true` if the video contains realistic altered or AI-generated content (YouTube's disclosure). Default `false`. |
| `playlistId` | Add the video to one of the channel's playlists after upload. Default `null`. |
| `defaultLanguage` | Video language, e.g. `en`, `hi`, `ta`, `es`. Default `null`. |
| `license` | `youtube` (default) or `creativeCommon`. |
| `embeddable` | Allow embedding on other sites. Default `true`. |
| `publicStatsViewable` | Show the like count publicly. Default `true`. |

Responses also include read-only `youtube` fields: `youtubePublishAt` (when YouTube will make a pre-uploaded video public), `processingStatus` (`processing`, `processed`, `failed`, `rejected` or `deleted`) and `warnings` (thumbnail/playlist problems).

`youtube` can also go inside an `overrides` entry (`"youtube"` or the channel's account id). YouTube descriptions are limited to 5,000 bytes. `placement: "story"`, `firstComment` and `commentRules` aren't supported on YouTube - comment fields are ignored for YouTube accounts (with a warning). YouTube posts come back with their `youtube` settings, and `platformPostId` is the YouTube video id once published.

> [!NOTE]
> Uploading a video takes longer than a photo post: a YouTube post moves to `publishing` while the file uploads and to `published` when YouTube has it. Listen for the `post.published` webhook rather than polling.
>
> A scheduled **public** video starts uploading up to an hour early, as private with YouTube's own publish time, so it goes live exactly on time. It shows as `published` (with `youtubePublishAt` in the future) once uploaded. After upload YouTube can still reject a video (duplicate, copyright, broken file) - the post then moves to `failed` with the reason and a `post.failed` webhook is sent.

Validation is all-or-nothing: if any account's post is invalid, nothing is created and you get a `422` listing every problem.

**Idempotency-Key** (recommended): if your request times out and you retry with the same key and body, you get the original response back instead of a duplicate post. Keys are remembered for 24 hours.

## 5. Manage posts

| Request | What it does |
| --- | --- |
| `GET /posts` | List posts. Filters: `status` (comma-separated), `accountId`, `platform`, `externalId`, `groupId`, `source` (`api`/`ui`/`bulk`), `from`/`to` (scheduled time). Paginate with `limit` (max 100) and the returned `nextCursor` → `?cursor=`. |
| `GET /posts/:id` | One post, including `permalinkUrl` and `error` once known. |
| `PATCH /posts/:id` | Change `content`, `media`, `coverUrl`, `scheduledAt` (`null` = back to draft), `publishNow`, `externalId`, `metadata`, and `youtube` (YouTube posts; only the fields you send change). Only for draft or scheduled posts. |
| `DELETE /posts/:id` | Cancel a draft/scheduled/failed post, or delete a published one from Facebook/Instagram/YouTube too. Add `?remote=false` to only remove it from HexaFloww. Returns `204`. |
| `POST /posts/:id/retry` | Re-queue a failed post now, or at `{ "scheduledAt": "…" }`. |

Post `status` is one of `draft`, `scheduled`, `publishing`, `published`, `failed`. Each post also has `content` (the caption actually used on that platform) and `customized` (`true` if that caption was written for this platform rather than shared). Posts from one request share a `groupId`.

## 6. First comment & auto-replies

Facebook and Instagram only - YouTube posts ignore these fields.

Add these when you create a post (needs the `social:engage` permission). They're saved with the scheduled post and **start working the moment it goes live** - nothing happens before that, and nothing touches your other posts.

```json
{
  "accountIds": [41, 42],
  "content": "New autumn drop 🍂",
  "media": [{ "url": "…" }],
  "scheduledAt": "2026-11-10T18:30:00+05:30",
  "firstComment": "#autumn #fashion #newdrop",
  "commentRules": [
    {
      "keyword": "price",
      "matchType": "contains",
      "action": "both",
      "reply": "Sent you a DM, {name} 📩",
      "replyVariants": ["Check your inbox!", "DM sent 🙌"],
      "dm": "Hi {name}! Here's the link: https://shop.example.com/autumn",
      "oncePerUser": true
    }
  ],
  "overrides": { "instagram": { "firstComment": "#autumn #reels" } }
}
```

- **`firstComment`** - posted automatically a few seconds after the post publishes (up to 2,200 characters; Instagram max 30 hashtags). If it fails it's retried, and the post itself stays live. Its result is in `firstComment.status` (`pending`, `posted`, `failed`) and the `post.first_comment` webhook.
- **`commentRules`** (up to 10 per post) - when a comment matches, we reply publicly, send a DM, or both:

| Field | Notes |
| --- | --- |
| `keyword` | Word or phrase to look for (not needed when `matchType` is `any`). Not case-sensitive. |
| `matchType` | `contains` (default), `exact`, `starts_with`, or `any` (every comment - max one per post). |
| `action` | `comment_reply`, `dm_reply`, `both`, or `hide`. |
| `reply` / `replyVariants` | Public reply, plus up to 4 variations picked at random - Meta flags identical repeated replies as spam. |
| `dm` | Private message. Meta allows **one per comment, within 7 days** of it. |
| `oncePerUser` | `true` (default) = act on each person once per post, however many times they comment. |

`{name}` is replaced with the commenter's first name. Both fields can be customised per platform or account in `overrides`, like captions. Stories don't have comments, so these are rejected for `placement: "story"`.

Each post in responses includes its `commentRules`, each with a `state`: `pending` (post not live yet), `live`, or `paused`.

**Managing rules later:**

| Request | What it does |
| --- | --- |
| `GET` / `POST /posts/:id/comment-rules` | List / add rules for one post - works before or after it publishes. |
| `GET` / `POST /accounts/:id/comment-rules` | Rules for the whole account (every post). `POST` with `platformPostId` targets one existing live post. `GET ?scope=account\|post\|all`. |
| `GET` / `PATCH` / `DELETE /comment-rules/:id` | Read, edit (send `"active": false` to pause), delete. |
| `POST /comment-rules/:id/backfill` | Apply a live rule to comments that are already on the post. |
| `POST /posts/:id/first-comment/retry` | Re-queue a failed first comment. |

## 7. Comments

| Request | What it does |
| --- | --- |
| `GET /posts/:id/comments` | Comments on one post (newest first, `cursor` pagination). |
| `GET /comments` | All comments - filter by `accountId`, `platformPostId`, `direction` (`in` / `out`), `since`. |
| `POST /comments/:id/reply` | Public reply - `{ "text": "…" }`. |
| `POST /comments/:id/dm` | Private reply (DM) - `{ "text": "…" }`. One per comment, within 7 days. |
| `POST /comments/:id/hide` / `unhide` | Hide or unhide on Facebook / Instagram. |
| `DELETE /comments/:id` | Delete it on Facebook / Instagram. |

Reading needs `social:read`; everything else needs `social:engage`.

## 8. Webhooks

Add an endpoint in **Settings → API Keys → Webhooks** and pick the events you want:

| Event | When |
| --- | --- |
| `post.published` | The post is live - includes `platformPostId`, `permalinkUrl` and its `commentRules` (now `live`). For YouTube, `platformPostId` is the video id and `permalinkUrl` the watch link. |
| `post.failed` | Publishing failed - `error.message` says why. |
| `post.deleted` | The post was deleted or cancelled. |
| `post.scheduled` | A post was created or rescheduled (off by default). |
| `account.disconnected` / `account.error` | An account can no longer publish. |
| `account.reconnect_due` | Meta access expires soon (14, 7, 3 and 1 days before). |
| `post.first_comment` | The automatic first comment was posted or failed - see `post.firstComment`. |
| `comment.rule_applied` | An auto-reply rule acted on a comment - `result` says `replied`, `dmSent`, `hidden`, or why it was `skipped` (`repeat_user`, `dm_window_expired`, `rate_limited`). |
| `comment.received` | Any new comment on a Facebook / Instagram post (off by default - can be a lot on popular posts). |

By default an endpoint only hears about posts created through the API; untick **Only posts created through the API** to get events for posts your team makes in HexaFloww too.

Each delivery is a `POST` like this:

```json
{ "id": "evt_8c1f…", "type": "post.published", "createdAt": "2026-11-10T13:00:04.000Z", "projectId": 7,
  "data": { "post": { "id": 9002, "platform": "instagram", "status": "published", "externalId": "cms-post-8812",
                      "content": "Autumn is here 🍂 …", "customized": true,
                      "permalinkUrl": "https://www.instagram.com/p/…", "metadata": { "campaign": "autumn" }, … } } }
```

**Verify the signature.** Every request carries `X-HexaFloww-Signature: t=<unix seconds>,v1=<hex>`. Compute HMAC-SHA256 of `` `${t}.${rawBody}` `` with your endpoint's signing secret, compare it to `v1` in constant time, and reject requests older than 5 minutes. `X-HexaFloww-Event-Id` is unique per event - use it to ignore duplicates.

Reply with any `2xx` within 10 seconds. Failed deliveries are retried after 1 min, 5 min, 30 min, 2 h, 6 h, 12 h and 24 h. An endpoint that keeps failing for 3 days is paused and your admins are notified. **Send test event** and **Resend** are on the endpoint card.

## Errors and limits

Errors always look like this:

```json
{ "error": { "code": "validation_failed", "message": "…", "details": [
  { "code": "media_required", "field": "media", "accountId": 42, "message": "Instagram posts need at least one image or video." }
] } }
```

| Status | Meaning |
| --- | --- |
| `401` | Missing, wrong or revoked API key. |
| `403` | Key lacks the scope (`insufficient_scope`), workspace locked (`workspace_locked`), or plan doesn't include social publishing (`feature_not_in_plan`). |
| `404` | Post not found in this project. |
| `409` | Post is publishing / not editable, or an `Idempotency-Key` conflict. |
| `422` | Invalid input - see `details`. |
| `429` | Rate limited (120 requests per minute per key). Wait for `Retry-After`. |

> [!TIP]
> Meta can still reject a valid-looking post at publish time (for example a non-JPG image on Instagram, or an expired connection). Subscribe to `post.failed` so you find out right away.
