เริ่มต้นใช้งาน
เริ่มต้นจาก workspace ใหม่ไปจนถึงการเผยแพร่หรือตั้งเวลาโพสต์แรกผ่าน API ภายในไม่กี่นาที
อัปเดตล่าสุด
เนื้อหาในหน้านี้
เริ่มต้นจาก Postkub workspace ใหม่ไปจนถึงการเผยแพร่หรือตั้งเวลาโพสต์แรกภายใน 5 นาที คุณตั้งค่า Brand เชื่อมต่อบัญชีโซเชียล และสร้าง scoped API key เพียงครั้งเดียวในเว็บแอป จากนั้นจึงเรียก REST API จากสคริปต์หรือ AI agent ของคุณได้ทันที
หมายเหตุ
REST API พร้อมใช้งานแล้ววันนี้ ส่วนตัวอย่างคำสั่ง postkub CLI ที่แสดงคู่กับ cURL ในหน้านี้เป็น client รุ่น preview ของ @postkub/cli ซึ่งยังไม่เผยแพร่บน npm คุณสามารถใช้ตัวอย่าง REST API ได้โดยตรงทันที
1. สร้าง Brand และเชื่อมต่อบัญชีโซเชียล
การตั้งค่าระดับเจ้าของต้องทำผ่าน human session ในแดชบอร์ดเว็บเสมอ และไม่เปิดให้ external API key เรียกใช้งาน
- สมัครบัญชีที่ /signup หรือเข้าสู่ระบบ workspace ของคุณ
- สร้าง Brand และเลือก IANA timezone เริ่มต้น (เช่น
Asia/Bangkok) - เชื่อมต่อบัญชีโซเชียลอย่างน้อยหนึ่งบัญชีเข้ากับ Brand นั้นผ่าน OAuth จนสถานะเป็น
active
เมื่อเชื่อมต่อบัญชีโซเชียลแล้ว สคริปต์หรือ external AI ของคุณจะสามารถสร้าง draft เผยแพร่ และตั้งเวลาโพสต์ไปยังบัญชีนั้นได้โดยไม่ต้องกลับมาทำซ้ำด้วยมือ
2. สร้าง scoped API key
เปิดหน้า API Settings ในแดชบอร์ดเว็บ แล้วสร้าง API key ใหม่
- ตั้งชื่อ key ให้สื่อความหมาย (เช่น
Production content agent) และเลือก environment (development,stagingหรือproduction) - เลือก Brand และ บัญชีโซเชียล ที่เชื่อมต่อแล้วซึ่งต้องการให้ key เข้าถึงได้
- เลือก actions ที่อนุญาต หรือคงค่าเริ่มต้นแบบ all-social-actions preset (ชุดสิทธิ์ social action ที่รองรับในปัจจุบัน ภายใต้ target ที่คุณเลือกเท่านั้น)
- กำหนดวันหมดอายุหากต้องการ จากนั้นกดสร้าง key
คัดลอก secret แบบ plaintext (pk_<env>_<secret>) เก็บไว้ทันที เนื่องจาก Postkub เก็บเฉพาะ salted hash และแสดง secret เพียงครั้งเดียว ควรเก็บไว้ใน environment variable แทนการเขียนลงในซอร์สโค้ดหรือประวัติคำสั่ง
export POSTKUB_API_KEY="<API_KEY>"
อ่านรายละเอียดเพิ่มเติมเรื่องรายการ scope การหมุนเวียน และความปลอดภัยของ key ได้ที่ Authentication & Scopes
3. ตรวจสอบ key ด้วย /api/v1/me
เรียก GET /api/v1/me เพื่อยืนยัน bearer token และตรวจดู workspace, Brand ID, account ID และ actions ที่ key ได้รับอนุญาต API key ที่ยังใช้งานได้ทุกตัวเรียก endpoint นี้ได้แม้ไม่มีสิทธิ์ brand:read หรือ account:read
curl -sS https://postkub.com/api/v1/me \
-H "Authorization: Bearer <API_KEY>"
คำสั่ง CLI ที่เทียบเท่า (preview):
postkub whoami --output json
ตัวอย่างผลลัพธ์:
{
"principalType": "api_key",
"workspaceId": "ws_example01",
"user": null,
"apiKey": {
"id": "key_example01",
"name": "Production content agent",
"prefix": "pk_prd_ab12c",
"environment": "production",
"revision": 1,
"expiresAt": null
},
"actions": [
"account:read",
"account:schedule",
"brand:read",
"post:cancel",
"post:create",
"post:publish",
"post:read",
"post:schedule",
"post:update"
],
"brandIds": ["brand_example01"],
"accountIds": ["acc_example01"],
"brands": [
{
"id": "brand_example01",
"name": "Acme Coffee",
"timezone": "Asia/Bangkok",
"createdAt": "2026-12-01T08:00:00.000Z"
}
],
"accounts": [
{
"id": "acc_example01",
"brandId": "brand_example01",
"provider": "meta",
"platform": "facebook",
"name": "Acme Coffee Page",
"handle": "@acmecoffee",
"timezone": "Asia/Bangkok",
"status": "active",
"createdAt": "2026-12-01T08:05:00.000Z"
}
]
}
4. ดูรายการบัญชีและตรวจสอบ capabilities
หาก key มีสิทธิ์ account:read คุณสามารถดึงรายการบัญชี (กรองด้วย brandId ได้) และตรวจดูความสามารถที่บัญชีแต่ละตัวรองรับก่อนส่งคำสั่งเผยแพร่
curl -sS "https://postkub.com/api/v1/accounts?brandId=brand_example01" \
-H "Authorization: Bearer <API_KEY>"
จากนั้นตรวจสอบ capabilities ของบัญชีเป้าหมาย:
curl -sS https://postkub.com/api/v1/accounts/acc_example01/capabilities \
-H "Authorization: Bearer <API_KEY>"
คำสั่ง CLI ที่เทียบเท่า (preview):
postkub accounts list --brand-id brand_example01 --output json
postkub capabilities get --account-id acc_example01 --output json
ตัวอย่างผลลัพธ์ capabilities:
{
"accountId": "acc_example01",
"allowedActions": [
"account:read",
"account:schedule",
"brand:read",
"post:cancel",
"post:create",
"post:publish",
"post:read",
"post:schedule",
"post:update"
],
"publishFormats": [
{
"format": "image",
"available": true,
"reason": "Live image publication is qualified for this account"
},
{
"format": "video",
"available": false,
"reason": "Live video publication is not qualified for this account yet"
}
],
"availability": {
"drafts": {
"available": true,
"reason": "Text and hosted-media drafts are enabled"
},
"publishing": {
"available": true,
"reason": "Publishing is enabled for this account"
},
"comments": {
"available": false,
"reason": "Comment actions are not granted to this key"
},
"firstComment": {
"available": true,
"reason": "A first comment can be attached to scheduled posts and is published right after the post goes out"
},
"insights": {
"available": false,
"reason": "Insight actions are not granted to this key"
}
}
}
เคล็ดลับ
ควรตรวจสอบ availability.publishing.available และ publishFormats ก่อนตั้งเวลาหรือเผยแพร่เสมอ หากความสามารถใดยังไม่พร้อมใช้งาน Postkub จะระบุเหตุผลไว้ให้ชัดเจนล่วงหน้า
5. สร้าง draft
คำขอเขียนข้อมูลทุกครั้งต้องส่ง UUID ที่ฝั่ง client สร้างขึ้นใน header Idempotency-Key การสร้างโพสต์จะบันทึกเป็น draft ที่ revision: 1 โดยยังไม่ส่งออกไปยังเครือข่ายโซเชียล และ draft เดียวกันนี้จะปรากฏบนแดชบอร์ดเว็บทันที
curl -sS -X POST https://postkub.com/api/v1/posts \
-H "Authorization: Bearer <API_KEY>" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 11111111-1111-4111-8111-111111111111" \
-d '{
"brandId": "brand_example01",
"socialAccountIds": ["acc_example01"],
"text": "Fresh seasonal roast drops Friday at 09:00."
}'
คำสั่ง CLI ที่เทียบเท่า (preview):
postkub posts create \
--brand-id brand_example01 \
--account-id acc_example01 \
--text "Fresh seasonal roast drops Friday at 09:00." \
--output json
ตัวอย่างผลลัพธ์ 201 Created:
{
"requestId": "11111111-1111-4111-8111-111111111111",
"post": {
"id": "post_example123",
"brandId": "brand_example01",
"status": "draft",
"revision": 1,
"text": "Fresh seasonal roast drops Friday at 09:00.",
"socialAccountIds": ["acc_example01"],
"mediaAssetIds": [],
"mediaUrls": [],
"mediaKind": "image",
"firstComment": null,
"firstCommentOverrides": [],
"authorActorType": "user",
"authorId": "user_example01",
"sourcePrincipalType": "api_key",
"sourcePrincipalId": "key_example01",
"createdAt": "2026-12-03T08:00:00.000Z",
"updatedAt": "2026-12-03T08:00:00.000Z",
"targets": [
{
"socialAccountId": "acc_example01",
"status": "pending"
}
],
"allowedActions": ["post:read", "post:update"]
},
"url": "/api/v1/posts/post_example123"
}
ต้องการแนบรูปภาพใช่ไหม คุณสามารถส่งลิงก์ HTTPS แบบ direct-download ที่เข้าถึงได้สาธารณะใน mediaUrls (หรือ --media-url แบบส่งซ้ำได้ใน CLI) ดูรายละเอียดและกฎการตรวจสอบได้ที่ Hosted Media
6. เผยแพร่ทันทีหรือตั้งเวลาโพสต์
การเผยแพร่และการตั้งเวลาเป็นคำขอแยกต่างหาก โดยใช้ Idempotency-Key UUID ใหม่ร่วมกับค่า expectedRevision ปัจจุบันของ draft
เผยแพร่ทันที
curl -sS -X POST https://postkub.com/api/v1/posts/post_example123/publish \
-H "Authorization: Bearer <API_KEY>" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 22222222-2222-4222-8222-222222222222" \
-d '{
"expectedRevision": 1,
"socialAccountIds": ["acc_example01"]
}'
คำสั่ง CLI ที่เทียบเท่า (preview):
postkub posts publish \
--id post_example123 \
--expected-revision 1 \
--account-id acc_example01 \
--output json
ตั้งเวลาโพสต์แทน
หากต้องการระบุเวลาที่แน่นอนตาม timezone ของบัญชี ให้เรียก POST /api/v1/posts/{id}/schedule พร้อม localTime, timezone และค่า fireAtUtc ที่ตรงกัน (หรือส่ง schedule: { nextSlot: true } เพื่อจอง queue slot รายสัปดาห์ถัดไปที่ว่างของบัญชี):
curl -sS -X POST https://postkub.com/api/v1/posts/post_example123/schedule \
-H "Authorization: Bearer <API_KEY>" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 33333333-3333-4333-8333-333333333333" \
-d '{
"expectedRevision": 1,
"targets": [
{
"socialAccountId": "acc_example01",
"localTime": "2026-12-10T09:00:00",
"timezone": "Asia/Bangkok",
"fireAtUtc": "2026-12-10T02:00:00.000Z"
}
]
}'
คำสั่ง CLI สำหรับจอง queue slot ถัดไป (preview):
postkub posts schedule \
--id post_example123 \
--expected-revision 1 \
--next-slot \
--account-id acc_example01 \
--output json
ทั้ง /publish และ /schedule จะตอบกลับด้วย 202 Accepted:
{
"requestId": "22222222-2222-4222-8222-222222222222",
"post": {
"id": "post_example123",
"brandId": "brand_example01",
"revision": 1,
"socialAccountIds": ["acc_example01"]
},
"targets": [
{
"socialAccountId": "acc_example01",
"publicationId": "pub_example456",
"revision": 1,
"status": "queued",
"scheduleMode": "now",
"fireAtUtc": "2026-12-03T08:01:00.000Z",
"localTime": null,
"resolvedLocalTime": null,
"timezone": null,
"cancellationRequested": false,
"allowedActions": ["cancel"],
"firstCommentState": "skipped",
"firstCommentError": null
}
],
"statusUrl": "/api/v1/posts/post_example123"
}
ข้อควรระวัง
สถานะ HTTP 202 Accepted หมายความว่า Postkub รับคำสั่งเผยแพร่ที่เปลี่ยนแปลงไม่ได้ไว้และนำเข้าคิวประมวลผลเบื้องหลังแล้ว ยังไม่ได้หมายความว่าเครือข่ายโซเชียลเผยแพร่โพสต์เสร็จสิ้นแล้ว
7. ตรวจสอบผลลัพธ์การเผยแพร่
เรียก GET /api/v1/posts/{id} (ตาม statusUrl ที่ได้จากผลตอบกลับ 202) เพื่อดูสถานะราย target หรือตั้งค่า Webhooks เพื่อรับ event ของวงจรชีวิตโพสต์
curl -sS https://postkub.com/api/v1/posts/post_example123 \
-H "Authorization: Bearer <API_KEY>"
คำสั่ง CLI ที่เทียบเท่า (preview):
postkub posts get --id post_example123 --output json
เมื่อ worker เผยแพร่เสร็จสิ้น ทั้ง status ระดับโพสต์และ targets[].publication.status จะเปลี่ยนเป็น published:
{
"id": "post_example123",
"brandId": "brand_example01",
"status": "published",
"revision": 1,
"text": "Fresh seasonal roast drops Friday at 09:00.",
"socialAccountIds": ["acc_example01"],
"mediaAssetIds": [],
"mediaUrls": [],
"mediaKind": "image",
"firstComment": null,
"firstCommentOverrides": [],
"authorActorType": "user",
"authorId": "user_example01",
"sourcePrincipalType": "api_key",
"sourcePrincipalId": "key_example01",
"createdAt": "2026-12-03T08:00:00.000Z",
"updatedAt": "2026-12-03T08:01:08.000Z",
"targets": [
{
"socialAccountId": "acc_example01",
"status": "published",
"publication": {
"socialAccountId": "acc_example01",
"publicationId": "pub_example456",
"revision": 3,
"status": "published",
"scheduleMode": "now",
"fireAtUtc": "2026-12-03T08:01:00.000Z",
"localTime": null,
"resolvedLocalTime": null,
"timezone": null,
"cancellationRequested": false,
"allowedActions": [],
"firstCommentState": "skipped",
"firstCommentError": null
}
}
],
"allowedActions": ["post:read"]
}
ขั้นตอนถัดไป
- Authentication & Scopes — ตาราง scope ทั้งหมด กฎ default-deny รวมถึงการหมุนเวียนและเพิกถอน key
- Your First Post — บทเรียนครบวงจรตั้งแต่สร้าง draft เผยแพร่ ตั้งเวลา ยกเลิก ไปจนถึงการ retry อย่างปลอดภัย
- Hosted Media — วิธีแนบสื่อผ่าน public HTTPS URL และกฎการตรวจสอบที่ Postkub บังคับใช้
- Scheduling — การตั้งเวลาแบบระบุเวลา การจอง queue slot รายสัปดาห์ การจัดการ DST และการเปลี่ยนเวลา
- Idempotency & Request Recovery, Errors และ Rate Limits — พื้นฐานความน่าเชื่อถือสำหรับระบบจริง
- เอกสารอ้างอิง API: Discovery, Posts และ Publications — สัญญา request และ response ฉบับเต็ม
- CLI และ MCP Server — เครื่องมือสำหรับ terminal และ AI client รุ่น preview
