สร้างและจัดการโพสต์
สร้าง อ่าน แก้ไข ลบ และ archive โพสต์ด้วย API key แบบ scoped
อัปเดตล่าสุด
เนื้อหาในหน้านี้
Post คือ record เนื้อหาที่มนุษย์และ API key แก้ไขร่วมกันผ่าน lifecycle เดียวกัน Key ต้องสร้าง draft ก่อนเสมอ ส่วนการเผยแพร่จะเกิดผ่าน operation publish และ schedule แยกต่างหากตามหน้า Publications ทุก mutation ในหน้านี้ต้องมี header Idempotency-Key และเมื่อแก้โพสต์ที่มีอยู่ต้องส่ง expectedRevision ปัจจุบันด้วย (ดู คู่มืออ้างอิง API)
สร้างโพสต์ (Create a post)
POST /api/v1/posts
สร้าง draft ใหม่ในระบบ draft จะถูกสร้างด้วยสถานะ draft เสมอ แม้จะเลือก target account ไว้แล้ว การ publish หรือ schedule เป็น action แยกที่ต้องยอมรับอีกขั้น Scopes: post:create CLI: postkub posts create MCP: posts_create
Headers
| ชื่อ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
| Idempotency-Key | UUID | ใช่ | รหัสประจำ mutation request ของ client ใช้ UUID เดิมซ้ำเมื่อ response หาย |
Body parameters
| ชื่อ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
| brandId | string | ใช่ | Brand ID ปลายทาง, ยาว 1-128 อักขระ |
| text | string | ใช่ | ข้อความตรงตามต้นฉบับ, 1-5000 UTF-16 code units, ห้ามเป็นช่องว่างล้วน ระบบเก็บตามที่ส่งมาโดยไม่ตัดช่องว่างหรือแปลงรูป |
| socialAccountIds | array ของ string | ไม่ | Audience ของ draft, 0-10 account ID แบบไม่ซ้ำ API key ต้องเลือกอย่างน้อย 1 account ส่วน draft แบบไม่มี target จะถูกปฏิเสธด้วย 403 TARGETLESS_DRAFT_OWNER_ONLY |
| mediaAssetIds | array ของ string | ไม่ | Verified media asset ID ตามลำดับ จาก media gateway ของ Web UI ที่ยืนยันตัวตนด้วย session (ฝั่งมนุษย์) |
| mediaUrls | array ของ string | ไม่ | HTTPS URL สตรีม media สาธารณะตามลำดับ, สูงสุด 10 รายการ, ไม่ซ้ำ, ยาวไม่เกิน 2048 อักขระต่อ URL ปฏิเสธหน้า viewer/share, host ส่วนตัว และ URL ที่ฝัง credential ดูที่ Hosted Media |
| mediaKind | string | ไม่ | image หรือ video ค่าเริ่มต้น image ต้องระบุเป็น video เมื่อใช้ hosted URL (ระบบไม่เดาจากนามสกุลไฟล์) และต้องตรงกับชนิดของ asset ที่ยืนยันแล้ว |
| videoCoverOffsets | array ของ object | ไม่ | Offset เฟรมปกวิดีโอราย target เป็นมิลลิวินาที (socialAccountId, offsetMs 0-2147483647) สำหรับ Instagram Reels หรือ TikTok เก็บไว้ที่ draft และตรวจ capability อีกครั้งตอนยอมรับ publication |
| videoCoverImages | array ของ object | ไม่ | Image asset ที่ยืนยันแล้วราย target (socialAccountId, mediaAssetId) สำหรับปก Instagram Reel หรือวิดีโอ YouTube |
| firstComment | string | ไม่ | ข้อความ first comment หลัก (ถ้าต้องการ), ยาวไม่เกิน 2200 อักขระ, ใช้กติกาเดียวกับ reply ระบบจะโพสต์หลัง target เผยแพร่สำเร็จ และขึ้นกับ capability ราย account ตอนยอมรับ |
| firstCommentOverrides | array ของ object | ไม่ | ค่า override ราย target (socialAccountId, text ไม่เกิน 2200) target ที่ไม่มีรายการจะใช้ firstComment หลัก |
โพสต์วิดีโอต้องมี media หนึ่งรายการเท่านั้น (asset หรือ URL) และผลรวมของ mediaAssetIds กับ mediaUrls ต้องไม่เกิน 35 รายการ
Request example
curl -sS -X POST https://postkub.com/api/v1/posts \
-H "Authorization: Bearer <API_KEY>" \
-H "Idempotency-Key: 7f6c2f1e-8b4a-4c3d-9e2f-1a2b3c4d5e6f" \
-H "Content-Type: application/json" \
-d '{
"brandId": "brand_example1",
"text": "New post from our agent",
"socialAccountIds": ["acc_example1"],
"mediaUrls": ["https://cdn.example.com/clips/launch.mp4"],
"mediaKind": "video",
"firstComment": "Links in the first comment"
}'
Response 201 Created
{
"requestId": "7f6c2f1e-8b4a-4c3d-9e2f-1a2b3c4d5e6f",
"post": {
"id": "post_example123",
"brandId": "brand_example1",
"status": "draft",
"revision": 1,
"text": "New post from our agent",
"socialAccountIds": ["acc_example1"],
"mediaAssetIds": [],
"mediaUrls": ["https://cdn.example.com/clips/launch.mp4"],
"mediaKind": "video",
"firstComment": "Links in the first comment",
"firstCommentOverrides": [],
"authorActorType": "user",
"authorId": "user_example1",
"sourcePrincipalType": "api_key",
"sourcePrincipalId": "key_example1",
"createdAt": "2026-12-03T09:00:00.000Z",
"updatedAt": "2026-12-03T09:00:00.000Z",
"targets": [
{ "socialAccountId": "acc_example1", "status": "pending" }
],
"allowedActions": ["post:read", "post:update", "post:delete", "post:publish", "post:schedule"]
},
"url": "/api/v1/posts/post_example123"
}
ถ้าเป็น idempotent replay ที่เหมือนเดิมทุกประการแต่ body เต็มที่เก็บไว้ไม่สามารถคืนได้อีก ระบบจะตอบด้วยสถานะเดิมพร้อม receipt แบบย่อ (requestId บวก post.id และ post.revision) แทน
| สถานะ | ความหมาย |
|---|---|
| 201 | สร้าง draft แล้ว (สถานะเป็น draft เสมอ) |
| 400 | Validation error หรือ media ไม่รองรับ (ดู Errors) |
| 401 | ต้องยืนยันตัวตน |
| 403 | Key ไม่มี post:create หรือขอ draft แบบไม่มี target (TARGETLESS_DRAFT_OWNER_ONLY) |
| 404 | ไม่พบ Brand หรืออยู่นอก scope ของ key |
| 409 | Idempotency conflict, target-brand conflict หรือ lock timeout |
List posts
GET /api/v1/posts
แสดงรายการโพสต์ที่ผู้เรียกมองเห็นได้พร้อมตัวกรอง item แต่ละรายการเป็น full projection เมื่อผู้เรียกมีสิทธิ์ครบทั้ง Brand และทุก target หรือเป็น partial projection (ฟิลด์น้อยกว่า, audience ลดเหลือเฉพาะส่วนที่มีสิทธิ์) เมื่อไม่ครบ Scopes: post:read CLI: postkub posts list MCP: posts_list
Query parameters
| ชื่อ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
| brandId | string | ไม่ | จำกัดเฉพาะ Brand ID ที่ระบุ |
| accountId | string | ไม่ | จำกัดเฉพาะโพสต์ที่ target account ID นี้ |
| status | string | ไม่ | ค่าใดค่าหนึ่งจาก draft, scheduled, publishing, published, failed, cancelled, needs_attention |
| from | string | ไม่ | จุดเริ่มช่วง (รวมปลายนี้), ISO date-time เขต UTC |
| to | string | ไม่ | จุดสิ้นสุดช่วง (รวมปลายนี้), ISO date-time เขต UTC โดย from ต้องน้อยกว่าหรือเท่ากับ to |
| cursor | string | ไม่ | Opaque cursor จาก nextCursor, ยาว 1-512 อักขระ |
| limit | integer | ไม่ | ขนาดหน้า, 1-100, ค่าเริ่มต้น 50 |
Request example
curl -sS "https://postkub.com/api/v1/posts?status=draft&limit=50" \
-H "Authorization: Bearer <API_KEY>"
Response 200 OK
{
"items": [
{
"id": "post_example123",
"brandId": "brand_example1",
"status": "draft",
"revision": 1,
"text": "New post from our agent",
"socialAccountIds": ["acc_example1"],
"mediaAssetIds": [],
"mediaUrls": ["https://cdn.example.com/clips/launch.mp4"],
"mediaKind": "video",
"firstComment": "Links in the first comment",
"firstCommentOverrides": [],
"authorActorType": "user",
"authorId": "user_example1",
"sourcePrincipalType": "api_key",
"sourcePrincipalId": "key_example1",
"createdAt": "2026-12-03T09:00:00.000Z",
"updatedAt": "2026-12-03T09:00:00.000Z",
"targets": [
{ "socialAccountId": "acc_example1", "status": "pending" }
],
"allowedActions": ["post:read", "post:update", "post:delete", "post:publish", "post:schedule"]
}
],
"nextCursor": null
}
item แบบ partial projection จะไม่มี brandId, mediaAssetIds, ฟิลด์ผู้เขียน และ timestamp โดย socialAccountIds จะระบุเฉพาะส่วนที่ผู้เรียกมีสิทธิ์ ดูที่ Pagination
| สถานะ | ความหมาย |
|---|---|
| 200 | คืนรายการ projection |
| 400 | Pagination หรือ cursor ไม่ถูกต้อง (ดู Errors) |
| 401 | ต้องยืนยันตัวตน |
| 403 | Key ไม่มี post:read |
ดูโพสต์เดียว (Get a post)
GET /api/v1/posts/{id}
คืนโพสต์หนึ่งรายการตาม projection ที่ผู้เรียกมีสิทธิ์: รูปแบบเต็มเมื่อมีสิทธิ์ครบทั้ง Brand และทุก target หรือรูปแบบย่อเมื่อไม่ครบ Scopes: post:read CLI: postkub posts get MCP: posts_get
Parameters
| ชื่อ | ตำแหน่ง | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|---|
| id | path | string | ใช่ | Post ID |
Request example
curl -sS https://postkub.com/api/v1/posts/post_example123 \
-H "Authorization: Bearer <API_KEY>"
Response 200 OK — รูปทรง projection เดียวกับตอนสร้างและ list เมื่อ target ใดมีงาน publication ที่ยอมรับแล้ว รายการ targets ของ target นั้นจะมี object publication บอกสถานะการรันปัจจุบันราย target (status, scheduleMode, fireAtUtc, allowedActions และ step state เช่น firstCommentState กับ coverState)
| สถานะ | ความหมาย |
|---|---|
| 200 | คืน projection ของโพสต์ |
| 400 | Post ID ไม่ถูกต้อง (ดู Errors) |
| 401 | ต้องยืนยันตัวตน |
| 403 | Key ไม่มี post:read |
| 404 | ไม่พบ draft (ตอบเท่ากันทุกกรณีที่มองไม่เห็น ไม่ว่าจะไม่มีอยู่หรืออยู่นอก scope) |
แก้โพสต์ (Update a post)
PATCH /api/v1/posts/{id}
แก้ไข draft ใน record เดิม แก้ได้เฉพาะโพสต์สถานะ draft สถานะอื่นจะได้ 409 UNSUPPORTED_STATE Key ต้องมีสิทธิ์ครบทั้ง union ของ target เดิมและ target ที่ขอ Scopes: post:update CLI: postkub posts update MCP: posts_update
Headers
| ชื่อ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
| Idempotency-Key | UUID | ใช่ | รหัสประจำ mutation request ของ client |
Body parameters
| ชื่อ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
| expectedRevision | integer | ใช่ | revision ปัจจุบันของโพสต์, ค่าต่ำสุด 1 ถ้าไม่ส่งจะได้ 428 REVISION_REQUIRED |
| text | string | ไม่ | ข้อความใหม่ (กติกาเดียวกับตอนสร้าง) |
| socialAccountIds | array ของ string | ไม่ | Audience ชุดใหม่, 0-10 ID แบบไม่ซ้ำ array ว่างจะล้างการเลือก (เฉพาะ owner session) |
| mediaAssetIds | array ของ string | ไม่ | แทนที่ verified media asset ID ทั้งชุด |
| mediaUrls | array ของ string | ไม่ | แทนที่ hosted URL ทั้งชุด ถ้าไม่ส่งจะคงค่าเดิม ส่ง array ว่างเพื่อลบทิ้ง |
| mediaKind | string | ไม่ | image หรือ video ถ้าไม่ส่งและไม่ได้แทนที่ media จะคงชนิดเดิม |
| videoCoverOffsets | array ของ object | ไม่ | แทนที่ offset ทั้งชุด ถ้าไม่ส่งจะคงเดิม array ว่างเพื่อล้าง |
| videoCoverImages | array ของ object | ไม่ | แทนที่รูปปกทั้งชุด ถ้าไม่ส่งจะคงเดิม array ว่างเพื่อล้าง |
| firstComment | string หรือ null | ไม่ | ไม่ส่งเพื่อคงเดิม, null เพื่อล้าง, ข้อความไม่ว่างเพื่อแทนที่ |
| firstCommentOverrides | array ของ object | ไม่ | ไม่ส่งเพื่อคง override เดิม หรือส่งชุดใหม่ทั้งชุด |
| brandId | string | ไม่ | เปลี่ยนไม่ได้ในส่วนนี้ ต้องตรงกับ brand เดิม |
Request example
curl -sS -X PATCH https://postkub.com/api/v1/posts/post_example123 \
-H "Authorization: Bearer <API_KEY>" \
-H "Idempotency-Key: 8a4b1f9e-2c3d-4e5f-8a9b-0c1d2e3f4a5b" \
-H "Content-Type: application/json" \
-d '{
"expectedRevision": 1,
"text": "Edited caption from our agent"
}'
Response 200 OK — โพสต์หลังแก้ไข เป็น full projection เสมอ (ผู้แก้ไขต้องมีสิทธิ์เต็มอยู่แล้ว)
| สถานะ | ความหมาย |
|---|---|
| 200 | แก้ draft สำเร็จ (หรือคืนผล replay ที่เหมือนเดิม) |
| 400 | Validation error หรือ media ไม่รองรับ (ดู Errors) |
| 401 | ต้องยืนยันตัวตน |
| 403 | Key ไม่มี post:update หรือไม่มีสิทธิ์ครบทุก target ที่เกี่ยวข้อง |
| 404 | ไม่พบ draft |
| 409 | REVISION_CONFLICT (revision เก่า พร้อม error.details.currentRevision), UNSUPPORTED_STATE (โพสต์ไม่ใช่ draft) หรือ idempotency conflict |
| 428 | REVISION_REQUIRED (ไม่ได้ส่ง expectedRevision) |
ลบ draft (Delete a draft)
DELETE /api/v1/posts/{id}
ลบ draft ในเครื่องที่ยังไม่มีการยอมรับ publication ออกถาวร โพสต์ที่มีงาน publication ที่ยอมรับแล้วลบไม่ได้ ให้ยกเลิกงานแล้วใช้ Archive โพสต์ (Archive a post) แทน Scopes: post:delete CLI: postkub posts delete MCP: posts_delete
Headers
| ชื่อ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
| Idempotency-Key | UUID | ใช่ | รหัสประจำ mutation request ของ client |
Body parameters
| ชื่อ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
| expectedRevision | integer | ใช่ | revision ปัจจุบันของโพสต์, ค่าต่ำสุด 1 |
Request example
curl -sS -X DELETE https://postkub.com/api/v1/posts/post_example123 \
-H "Authorization: Bearer <API_KEY>" \
-H "Idempotency-Key: 9b5c2a0f-3d4e-4f6a-9b0c-1d2e3f4a5b6c" \
-H "Content-Type: application/json" \
-d '{ "expectedRevision": 2 }'
Response 200 OK
{
"requestId": "9b5c2a0f-3d4e-4f6a-9b0c-1d2e3f4a5b6c",
"deletedPost": {
"id": "post_example123",
"brandId": "brand_example1",
"deletedRevision": 2,
"status": "deleted",
"socialAccountIds": ["acc_example1"]
}
}
| สถานะ | ความหมาย |
|---|---|
| 200 | ลบ draft แล้ว หรือคืน receipt เดิมจากการ replay ที่เหมือนเดิม |
| 400 | Validation error (ดู Errors) |
| 401 | ต้องยืนยันตัวตน |
| 403 | Key ไม่มี post:delete หรือไม่มีสิทธิ์ครบทุก target ที่เกี่ยวข้อง |
| 404 | ไม่พบ draft |
| 409 | UNSUPPORTED_STATE (โพสต์ไม่ใช่ draft ที่ยังไม่มีการยอมรับ), REVISION_CONFLICT หรือ idempotency conflict |
| 428 | REVISION_REQUIRED (ไม่ได้ส่ง expectedRevision) |
Archive โพสต์ (Archive a post)
POST /api/v1/posts/{id}/archive
Archive โพสต์ที่จบแล้ว (published, failed หรือ cancelled โดยไม่มีงาน publication ค้าง) ออกจากรายการที่ใช้งานอยู่ draft และโพสต์ที่มี publication ค้าง archive ไม่ได้ Scopes: post:delete ไม่มีคำสั่ง CLI หรือ MCP tool สำหรับ operation นี้
Headers
| ชื่อ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
| Idempotency-Key | UUID | ใช่ | รหัสประจำ mutation request ของ client |
Body parameters
| ชื่อ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
| expectedRevision | integer | ใช่ | revision ปัจจุบันของโพสต์, ค่าต่ำสุด 1 |
Request example
curl -sS -X POST https://postkub.com/api/v1/posts/post_example123/archive \
-H "Authorization: Bearer <API_KEY>" \
-H "Idempotency-Key: 0c6d3b1a-4e5f-4a7b-0c1d-2e3f4a5b6c7d" \
-H "Content-Type: application/json" \
-d '{ "expectedRevision": 3 }'
Response 200 OK
{
"requestId": "0c6d3b1a-4e5f-4a7b-0c1d-2e3f4a5b6c7d",
"archivedPost": {
"id": "post_example123",
"brandId": "brand_example1",
"revision": 4,
"archivedAt": "2026-12-03T10:00:00.000Z",
"socialAccountIds": ["acc_example1"]
}
}
การ archive จะเพิ่ม revision ของโพสต์ จึงต้องส่ง expectedRevision ก่อนการ archive
| สถานะ | ความหมาย |
|---|---|
| 200 | Archive โพสต์แล้ว (หรือคืนผล replay ที่เหมือนเดิม) |
| 400 | Validation error (ดู Errors) |
| 401 | ต้องยืนยันตัวตน |
| 403 | Key ไม่มี post:delete หรือไม่มีสิทธิ์ครบทุก target ที่เกี่ยวข้อง |
| 404 | ไม่พบโพสต์ |
| 409 | UNSUPPORTED_STATE (archive ได้เฉพาะโพสต์ที่จบแล้วและไม่มี publication ค้าง), REVISION_CONFLICT หรือ idempotency conflict |
| 428 | REVISION_REQUIRED (ไม่ได้ส่ง expectedRevision) |
