สร้างและจัดการโพสต์

สร้าง อ่าน แก้ไข ลบ และ archive โพสต์ด้วย API key แบบ scoped

อัปเดตล่าสุด

เปิดใน Claudeเปิดใน ChatGPT
เนื้อหาในหน้านี้

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-KeyUUIDใช่รหัสประจำ mutation request ของ client ใช้ UUID เดิมซ้ำเมื่อ response หาย

Body parameters

ชื่อชนิดจำเป็นคำอธิบาย
brandIdstringใช่Brand ID ปลายทาง, ยาว 1-128 อักขระ
textstringใช่ข้อความตรงตามต้นฉบับ, 1-5000 UTF-16 code units, ห้ามเป็นช่องว่างล้วน ระบบเก็บตามที่ส่งมาโดยไม่ตัดช่องว่างหรือแปลงรูป
socialAccountIdsarray ของ stringไม่Audience ของ draft, 0-10 account ID แบบไม่ซ้ำ API key ต้องเลือกอย่างน้อย 1 account ส่วน draft แบบไม่มี target จะถูกปฏิเสธด้วย 403 TARGETLESS_DRAFT_OWNER_ONLY
mediaAssetIdsarray ของ stringไม่Verified media asset ID ตามลำดับ จาก media gateway ของ Web UI ที่ยืนยันตัวตนด้วย session (ฝั่งมนุษย์)
mediaUrlsarray ของ stringไม่HTTPS URL สตรีม media สาธารณะตามลำดับ, สูงสุด 10 รายการ, ไม่ซ้ำ, ยาวไม่เกิน 2048 อักขระต่อ URL ปฏิเสธหน้า viewer/share, host ส่วนตัว และ URL ที่ฝัง credential ดูที่ Hosted Media
mediaKindstringไม่image หรือ video ค่าเริ่มต้น image ต้องระบุเป็น video เมื่อใช้ hosted URL (ระบบไม่เดาจากนามสกุลไฟล์) และต้องตรงกับชนิดของ asset ที่ยืนยันแล้ว
videoCoverOffsetsarray ของ objectไม่Offset เฟรมปกวิดีโอราย target เป็นมิลลิวินาที (socialAccountId, offsetMs 0-2147483647) สำหรับ Instagram Reels หรือ TikTok เก็บไว้ที่ draft และตรวจ capability อีกครั้งตอนยอมรับ publication
videoCoverImagesarray ของ objectไม่Image asset ที่ยืนยันแล้วราย target (socialAccountId, mediaAssetId) สำหรับปก Instagram Reel หรือวิดีโอ YouTube
firstCommentstringไม่ข้อความ first comment หลัก (ถ้าต้องการ), ยาวไม่เกิน 2200 อักขระ, ใช้กติกาเดียวกับ reply ระบบจะโพสต์หลัง target เผยแพร่สำเร็จ และขึ้นกับ capability ราย account ตอนยอมรับ
firstCommentOverridesarray ของ 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 เสมอ)
400Validation error หรือ media ไม่รองรับ (ดู Errors)
401ต้องยืนยันตัวตน
403Key ไม่มี post:create หรือขอ draft แบบไม่มี target (TARGETLESS_DRAFT_OWNER_ONLY)
404ไม่พบ Brand หรืออยู่นอก scope ของ key
409Idempotency 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

ชื่อชนิดจำเป็นคำอธิบาย
brandIdstringไม่จำกัดเฉพาะ Brand ID ที่ระบุ
accountIdstringไม่จำกัดเฉพาะโพสต์ที่ target account ID นี้
statusstringไม่ค่าใดค่าหนึ่งจาก draft, scheduled, publishing, published, failed, cancelled, needs_attention
fromstringไม่จุดเริ่มช่วง (รวมปลายนี้), ISO date-time เขต UTC
tostringไม่จุดสิ้นสุดช่วง (รวมปลายนี้), ISO date-time เขต UTC โดย from ต้องน้อยกว่าหรือเท่ากับ to
cursorstringไม่Opaque cursor จาก nextCursor, ยาว 1-512 อักขระ
limitintegerไม่ขนาดหน้า, 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
400Pagination หรือ cursor ไม่ถูกต้อง (ดู Errors)
401ต้องยืนยันตัวตน
403Key ไม่มี post:read

ดูโพสต์เดียว (Get a post)

GET /api/v1/posts/{id}

คืนโพสต์หนึ่งรายการตาม projection ที่ผู้เรียกมีสิทธิ์: รูปแบบเต็มเมื่อมีสิทธิ์ครบทั้ง Brand และทุก target หรือรูปแบบย่อเมื่อไม่ครบ Scopes: post:read CLI: postkub posts get MCP: posts_get

Parameters

ชื่อตำแหน่งชนิดจำเป็นคำอธิบาย
idpathstringใช่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 ของโพสต์
400Post ID ไม่ถูกต้อง (ดู Errors)
401ต้องยืนยันตัวตน
403Key ไม่มี 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-KeyUUIDใช่รหัสประจำ mutation request ของ client

Body parameters

ชื่อชนิดจำเป็นคำอธิบาย
expectedRevisionintegerใช่revision ปัจจุบันของโพสต์, ค่าต่ำสุด 1 ถ้าไม่ส่งจะได้ 428 REVISION_REQUIRED
textstringไม่ข้อความใหม่ (กติกาเดียวกับตอนสร้าง)
socialAccountIdsarray ของ stringไม่Audience ชุดใหม่, 0-10 ID แบบไม่ซ้ำ array ว่างจะล้างการเลือก (เฉพาะ owner session)
mediaAssetIdsarray ของ stringไม่แทนที่ verified media asset ID ทั้งชุด
mediaUrlsarray ของ stringไม่แทนที่ hosted URL ทั้งชุด ถ้าไม่ส่งจะคงค่าเดิม ส่ง array ว่างเพื่อลบทิ้ง
mediaKindstringไม่image หรือ video ถ้าไม่ส่งและไม่ได้แทนที่ media จะคงชนิดเดิม
videoCoverOffsetsarray ของ objectไม่แทนที่ offset ทั้งชุด ถ้าไม่ส่งจะคงเดิม array ว่างเพื่อล้าง
videoCoverImagesarray ของ objectไม่แทนที่รูปปกทั้งชุด ถ้าไม่ส่งจะคงเดิม array ว่างเพื่อล้าง
firstCommentstring หรือ nullไม่ไม่ส่งเพื่อคงเดิม, null เพื่อล้าง, ข้อความไม่ว่างเพื่อแทนที่
firstCommentOverridesarray ของ objectไม่ไม่ส่งเพื่อคง override เดิม หรือส่งชุดใหม่ทั้งชุด
brandIdstringไม่เปลี่ยนไม่ได้ในส่วนนี้ ต้องตรงกับ 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 ที่เหมือนเดิม)
400Validation error หรือ media ไม่รองรับ (ดู Errors)
401ต้องยืนยันตัวตน
403Key ไม่มี post:update หรือไม่มีสิทธิ์ครบทุก target ที่เกี่ยวข้อง
404ไม่พบ draft
409REVISION_CONFLICT (revision เก่า พร้อม error.details.currentRevision), UNSUPPORTED_STATE (โพสต์ไม่ใช่ draft) หรือ idempotency conflict
428REVISION_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-KeyUUIDใช่รหัสประจำ mutation request ของ client

Body parameters

ชื่อชนิดจำเป็นคำอธิบาย
expectedRevisionintegerใช่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 ที่เหมือนเดิม
400Validation error (ดู Errors)
401ต้องยืนยันตัวตน
403Key ไม่มี post:delete หรือไม่มีสิทธิ์ครบทุก target ที่เกี่ยวข้อง
404ไม่พบ draft
409UNSUPPORTED_STATE (โพสต์ไม่ใช่ draft ที่ยังไม่มีการยอมรับ), REVISION_CONFLICT หรือ idempotency conflict
428REVISION_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-KeyUUIDใช่รหัสประจำ mutation request ของ client

Body parameters

ชื่อชนิดจำเป็นคำอธิบาย
expectedRevisionintegerใช่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

สถานะความหมาย
200Archive โพสต์แล้ว (หรือคืนผล replay ที่เหมือนเดิม)
400Validation error (ดู Errors)
401ต้องยืนยันตัวตน
403Key ไม่มี post:delete หรือไม่มีสิทธิ์ครบทุก target ที่เกี่ยวข้อง
404ไม่พบโพสต์
409UNSUPPORTED_STATE (archive ได้เฉพาะโพสต์ที่จบแล้วและไม่มี publication ค้าง), REVISION_CONFLICT หรือ idempotency conflict
428REVISION_REQUIRED (ไม่ได้ส่ง expectedRevision)