# Post (/th/growsocmed/docs/developers/posts)

สร้าง ตั้งเวลา แก้ไข ลองใหม่ ยกเลิก และนำ post ออก

post หนึ่งรายการมีข้อความและรายการสื่อหนึ่งชุด และมี **target** หนึ่งรายการต่อแต่ละบัญชีปลายทาง แต่ละ target สามารถแทนที่ข้อความและสื่อได้ และมีตัวเลือกของแพลตฟอร์ม สถานะของ post เป็นไปตาม target ของมัน

## สร้าง post [#สร้าง-post]

```bash
curl -X POST https://socmed.growpaces.com/api/v1/posts \
  -H "Authorization: Bearer gs_..." \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: launch-2026-12-01" \
  -d '{
    "text": "Our December collection is here.",
    "media_ids": ["0193…"],
    "targets": [
      { "account_id": "6b1e…" },
      { "account_id": "a07c…", "text": "December collection, out now. Link in bio." },
      { "account_id": "c3d4…", "options": { "title": "December collection", "made_for_kids": false } }
    ],
    "scheduled_at": "2026-12-01T09:00:00+07:00"
  }'
```

| ฟิลด์ | |
| --- | --- |
| `text` | ไม่เกิน 70,000 ตัวอักษร แต่ละแพลตฟอร์มมีขีดจำกัดที่ต่ำกว่าของตัวเอง |
| `media_ids` | ไม่เกิน 20 ไฟล์จากคลังสื่อ ตามลำดับ ต้องมีสถานะ `ready` |
| `targets` | 1 ถึง 50 บัญชี แต่ละบัญชีได้ครั้งเดียว `text` และ `media_ids` ใน target จะแทนที่ของ post สำหรับบัญชีนั้น |
| `targets[].options` | ตัวเลือกของแพลตฟอร์ม ดูด้านล่าง |
| `scheduled_at` | ISO 8601 พร้อม offset เว้นว่างไว้ (หรือใส่เวลาในอดีต) เพื่อเผยแพร่ทันที |
| `idea_id` | ไอเดียที่เป็นที่มาของ post ดู [ไอเดีย](/th/growsocmed/docs/developers/ideas) |

ทุก target จะถูกตรวจสอบก่อนสร้างสิ่งใด: ความยาวข้อความ ประเภทสื่อ ขนาด อัตราส่วนและความยาว จำนวนไฟล์ และตัวเลือกที่จำเป็น หากมีบัญชีหนึ่งรับ post ไม่ได้ request ทั้งหมดจะล้มเหลวด้วย `400 validation_failed` และ `details.targets` จะแสดงปัญหาแยกตามบัญชี:

```json
{
  "error": {
    "code": "validation_failed",
    "message": "Some accounts cannot take this post",
    "details": { "targets": [ { "account_id": "6b1e…", "issues": [ { "code": "text_too_long", "max": 500, "length": 612 } ] } ] }
  }
}
```

รหัสปัญหาอื่นๆ ได้แก่ `media_required`, `too_many_media`, `mixed_media`, `media_type_not_supported`, `media_too_large`, `aspect_ratio_invalid`, `video_duration_invalid`, `too_many_videos`, `option_required`, `option_invalid`, `account_expired`, `account_not_found` และ `media_unavailable` อ่านขีดจำกัดปัจจุบันได้ด้วย [`GET /platform-rules`](/th/growsocmed/docs/api-reference/posts/get-platform-rules) หรือที่หน้า [แพลตฟอร์ม](/th/growsocmed/docs/platforms)

การตอบกลับคือ `201` พร้อม `{ post, replayed }`

### ตัวเลือกของแพลตฟอร์ม [#ตัวเลือกของแพลตฟอร์ม]

ตัวเลือกอยู่ใน `targets[].options` ของบัญชีที่เกี่ยวข้อง ตัวเลือกหลักๆ:

| แพลตฟอร์ม | ตัวเลือก |
| --- | --- |
| YouTube | `title` (จำเป็น ไม่เกิน 100 ตัวอักษร), `made_for_kids` (จำเป็น `true` หรือ `false`), `privacy`: `public`, `unlisted` หรือ `private` |
| TikTok | `privacy_level` (จำเป็น หนึ่งใน `PUBLIC_TO_EVERYONE`, `MUTUAL_FOLLOW_FRIENDS`, `FOLLOWER_OF_CREATOR`, `SELF_ONLY`), `disable_comment`, `disable_duet`, `disable_stitch`, `brand_content_toggle`, `brand_organic_toggle`, `is_aigc`, `title` (post รูปภาพ ไม่เกิน 90 ตัวอักษร), `post_mode`: `direct` หรือ `draft` |
| Pinterest | `board_id` (จำเป็น), `title`, `link`, `alt_text` |
| Instagram | `format`: `feed` หรือ `story` (Stories มีได้หนึ่งไฟล์พอดี), `collaborators` (ไม่เกิน 3), `trial`, `thumb_offset_ms` |
| Threads | `reply_control`, `topic_tag`, `link_attachment`, `poll` (2–4 ตัวเลือก สำหรับ post ข้อความ), `thread` (post ต่อเนื่องไม่เกิน 10 รายการ) |
| Facebook Page | `video_as`: `reel` หรือ `video`, `link` (post ข้อความ) |
| LinkedIn | `visibility`: `PUBLIC` หรือ `CONNECTIONS`, `document_title` |
| Telegram | `disable_notification` |
| Instagram, Facebook Page, TikTok | `first_comment`: คอมเมนต์ที่บัญชีเพิ่มไว้ใต้ post |

post ไปยัง X ชำระจากยอดเงินของเจ้าของ workspace

## สถานะ [#สถานะ]

| สถานะ post | ความหมาย |
| --- | --- |
| `scheduled` | รอถึงเวลา |
| `publishing` | กำลังส่ง |
| `published` | เผยแพร่แล้วในทุกบัญชี |
| `partial` | เผยแพร่ในบางบัญชี ล้มเหลวในบัญชีอื่น |
| `failed` | ล้มเหลวในทุกบัญชี |
| `canceled` | ถูกยกเลิกก่อนเผยแพร่ |

แต่ละ target มีสถานะของตัวเอง (`pending`, `publishing`, `published`, `failed`, `canceled`) มี `permalink` เมื่อเผยแพร่แล้ว และมี `error_code` และ `error_message` เมื่อล้มเหลว post ที่เกินขีดจำกัดการเผยแพร่ 24 ชั่วโมงของแพลตฟอร์มจะรอจนกว่าจะมีโควตาว่าง ไม่ล้มเหลว ตรวจสอบโควตาที่เหลือได้ด้วย [`GET /accounts/{id}/publishing-limit`](/th/growsocmed/docs/api-reference/accounts/get-publishing-limit)

[webhook](/th/growsocmed/docs/developers/webhooks) `post.published` และ `post.failed` จะแจ้งเมื่อแต่ละ target เสร็จสิ้น คุณจึงไม่ต้อง poll

## ดูรายการและอ่าน [#ดูรายการและอ่าน]

- [`GET /posts`](/th/growsocmed/docs/api-reference/posts/list-posts): เวลาตั้งล่าสุดก่อน กรองด้วย `status`, `from` และ `to` (เวลาที่ตั้งไว้) หรือ `view=scheduled` (ที่ยังไม่เผยแพร่ ใกล้สุดก่อน) และ `view=history` แบ่งหน้าด้วย `cursor`
- [`GET /posts/{id}`](/th/growsocmed/docs/api-reference/posts/get-post): post หนึ่งรายการพร้อม target
- [`GET /posts/counts`](/th/growsocmed/docs/api-reference/posts/count-posts): จำนวน post ตามสถานะ

## แก้ไข ลองใหม่ ยกเลิก นำออก [#แก้ไข-ลองใหม่-ยกเลิก-นำออก]

- [`PATCH /posts/{id}`](/th/growsocmed/docs/api-reference/posts/update-post) แก้ไขข้อความ สื่อ เวลา หรือ `targets` แยกตามบัญชี post ที่ตั้งเวลาไว้แก้ไขได้ทุกบัญชี post ที่เป็น `failed` หรือ `partial` แก้ไขได้เฉพาะบัญชีที่ล้มเหลว (เปลี่ยนเวลาไม่ได้) จากนั้นจึงลองใหม่ เนื้อหาใหม่จะถูกตรวจสอบเหมือน post ใหม่
- [`POST /posts/{id}/retry`](/th/growsocmed/docs/api-reference/posts/retry-post) เผยแพร่บัญชีที่ล้มเหลวอีกครั้งทันที
- [`DELETE /posts/{id}`](/th/growsocmed/docs/api-reference/posts/cancel-post) ยกเลิกบัญชีที่ยังไม่ได้เผยแพร่ บัญชีที่เผยแพร่แล้วยังคงเผยแพร่อยู่
- [`POST /posts/{id}/remove`](/th/growsocmed/docs/api-reference/posts/remove-post) นำ post ที่เสร็จสิ้นแล้ว (เผยแพร่แล้ว ล้มเหลว หรือถูกยกเลิก) ออกจากประวัติของ GrowSocmed จะไม่มีการลบสิ่งใดบนแพลตฟอร์ม

## นำเข้าจาก CSV [#นำเข้าจาก-csv]

[`POST /posts/import`](/th/growsocmed/docs/api-reference/posts/import-posts) ตั้งเวลา post ได้สูงสุด 100 รายการไปยังบัญชีเดียวจากข้อความ CSV ส่ง `account_id`, `csv` (คอลัมน์ `time`, `text` และ `media` หรือ `waktu`, `teks` และ `media` หากมี URL สื่อหลายรายการให้คั่นด้วย `|`) และ `timezone` ของเวลา (ค่าเริ่มต้นคือ `Asia/Jakarta`) `dry_run` มีค่าเริ่มต้นเป็น `true` และจะตรวจสอบแถวเท่านั้น ส่ง `false` เพื่อสร้าง post URL ของสื่อต้องเป็นที่อยู่สาธารณะ `https://` การนำเข้าไฟล์เดิมซ้ำจะไม่สร้างรายการซ้ำ