Insights
อ่าน metric ของ account และ post ที่บันทึกไว้, การอ่านแบบ batch และประวัติ metric รายวัน พร้อม freshness และเหตุผลช่องว่างที่ชัดเจน
อัปเดตล่าสุด
เนื้อหาในหน้านี้
Endpoint กลุ่ม insights คืนค่า metric ที่ Postkub sync มาจาก account ที่เชื่อมต่อแล้วเท่านั้น ไม่มีการแต่งตัวเลขขึ้นมา ทุก response จะรายงาน freshness (fresh, stale หรือ never_synced) และ lastSyncedAt เมื่อช่วงที่ขอยังไม่สดใหม่ การอ่านจะยังคืน snapshot ล่าสุดที่บันทึกไว้กลับมา พร้อมจัดคิว sync พื้นหลังสำหรับครั้งหน้า metric ที่ขาดหรือไม่รองรับจะระบุชัดเจน คือ value เป็น null พร้อม unavailableReason ที่บอกเหตุผลแบบ machine-readable endpoint ทุกตัวต้องมี insight:read สำหรับ API key ส่วน session จะอ่านได้ทั้ง workspace
กฎช่วงเวลาใช้กับทุก endpoint คือ ส่ง rangeStartUtc และ rangeEndUtc เป็นคู่ ISO instant โดย start ต้องอยู่ก่อน end และหน้าต่างกว้างได้สูงสุด 90 วัน หากไม่ส่งทั้งคู่จะใช้ช่วงเริ่มต้นคือ 30 วันล่าสุดจนถึงปัจจุบัน เวลาทั้งหมดเป็น UTC
อ่าน insights ของ account (Read account insights)
GET /api/v1/accounts/{id}/insights
อ่าน insight snapshot ที่บันทึกไว้ของ account หนึ่งตัวในช่วงที่ขอ Scopes: insight:read CLI: postkub insights account MCP: insights_account
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| id | path | string | Yes | Social account ID |
| rangeStartUtc | query | string | คู่กับ rangeEndUtc | ISO instant, จุดเริ่มหน้าต่างช่วง |
| rangeEndUtc | query | string | คู่กับ rangeStartUtc | ISO instant, จุดสิ้นสุดหน้าต่างช่วง ห่างจาก start ได้สูงสุด 90 วัน |
Request example
curl -sS "https://postkub.com/api/v1/accounts/acc_example1/insights?rangeStartUtc=2026-11-04T00:00:00.000Z&rangeEndUtc=2026-12-04T00:00:00.000Z" \
-H "Authorization: Bearer <API_KEY>"
Response 200 OK
{
"accountId": "acc_example1",
"range": { "startUtc": "2026-11-04T00:00:00.000Z", "endUtc": "2026-12-04T00:00:00.000Z" },
"freshness": "fresh",
"lastSyncedAt": "2026-12-04T07:45:00.000Z",
"metrics": [
{ "name": "impressions", "value": 1200, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "reach", "value": 980, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "likes", "value": 154, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "comments", "value": 23, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "shares", "value": 12, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "saves", "value": null, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": "unsupported_by_provider" },
{ "name": "video_views", "value": 3100, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "profile_views", "value": 45, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "followers", "value": 1261, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null }
]
}
อาร์เรย์ metrics จะระบุชื่อเด้าเดียวกันเสมอเก้าชื่อ ได้แก่ impressions, reach, likes, comments, shares, saves, video_views, profile_views, followers โดย unit เป็น count หรือ milliseconds เมื่อ metric ใดไม่มีค่า unavailableReason จะอธิบายเหตุผล ได้แก่ unsupported_by_provider, not_available_yet, permission_denied หรือ unknown โดย API ไม่เติมช่องว่างด้วยศูนย์หรือการเดา freshness เป็น fresh เมื่อ snapshot ถูก sync ภายใน 15 นาทีล่าสุด ส่วน stale และ never_synced จะยังคืนข้อมูลที่บันทึกไว้กลับมาพร้อมจัดคิว refresh
| Status | Meaning |
|---|---|
| 200 | ได้รับ snapshot ที่บันทึกไว้ (อาจยังไม่สดใหม่) |
| 400 | ช่วง UTC ไม่ถูกต้อง (ดู Errors) |
| 401 | ต้องยืนยันตัวตน |
| 403 | Key ไม่มี insight:read |
| 404 | ไม่พบ account หรืออยู่นอก scope ของ key |
อ่าน insights ของ post (Read post insights)
GET /api/v1/posts/{id}/insights
อ่าน insights ที่บันทึกไว้ของ post หนึ่งโพสต์ โดยมีหนึ่งรายการต่อ target account ที่ผู้เรียกมองเห็นได้ response จะสะท้อนช่วงที่ขอกลับมา แต่ sync เบื้องหลังจะดึง insight ตลอดอายุโพสต์ของ provider เสมอ จึงควรถือว่าค่าที่ได้เป็นตัวเลขตลอดอายุ Scopes: insight:read CLI: postkub insights post MCP: insights_post
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| id | path | string | Yes | Post ID |
| rangeStartUtc | query | string | คู่กับ rangeEndUtc | ISO instant, จุดเริ่มหน้าต่างช่วง |
| rangeEndUtc | query | string | คู่กับ rangeStartUtc | ISO instant, จุดสิ้นสุดหน้าต่างช่วง ห่างจาก start ได้สูงสุด 90 วัน |
Request example
curl -sS "https://postkub.com/api/v1/posts/post_example123/insights" \
-H "Authorization: Bearer <API_KEY>"
Response 200 OK
{
"postId": "post_example123",
"range": { "startUtc": "2026-11-04T00:00:00.000Z", "endUtc": "2026-12-04T00:00:00.000Z" },
"targets": [
{
"socialAccountId": "acc_example1",
"freshness": "never_synced",
"lastSyncedAt": null,
"metrics": [
{ "name": "impressions", "value": null, "unit": "count", "asOf": null, "unavailableReason": "not_available_yet" },
{ "name": "reach", "value": null, "unit": "count", "asOf": null, "unavailableReason": "not_available_yet" },
{ "name": "likes", "value": null, "unit": "count", "asOf": null, "unavailableReason": "not_available_yet" },
{ "name": "comments", "value": null, "unit": "count", "asOf": null, "unavailableReason": "not_available_yet" },
{ "name": "shares", "value": null, "unit": "count", "asOf": null, "unavailableReason": "not_available_yet" },
{ "name": "saves", "value": null, "unit": "count", "asOf": null, "unavailableReason": "not_available_yet" },
{ "name": "video_views", "value": null, "unit": "count", "asOf": null, "unavailableReason": "not_available_yet" },
{ "name": "profile_views", "value": null, "unit": "count", "asOf": null, "unavailableReason": "not_available_yet" },
{ "name": "followers", "value": null, "unit": "count", "asOf": null, "unavailableReason": "not_available_yet" }
],
"unavailableReason": "not_published"
}
]
}
target ที่ publication ยังไม่ก่อกำเนิด provider post จะตอบ freshness: never_synced พร้อม unavailableReason: not_published ส่วน target ที่เผยแพร่แล้วจะใช้รูปแบบ metric เดียวกับ endpoint ของ account key จะเห็นเฉพาะ target ใน scope ของตัวเอง และ post ที่ไม่มี target ที่เข้าถึงได้จะตอบ 404
| Status | Meaning |
|---|---|
| 200 | ได้รับ snapshot ราย target (อาจยังไม่สดใหม่) |
| 400 | ช่วง UTC ไม่ถูกต้อง (ดู Errors) |
| 401 | ต้องยืนยันตัวตน |
| 403 | Key ไม่มี insight:read |
| 404 | ไม่พบ post หรือไม่มี target account ที่เข้าถึงได้ |
อ่าน insights ของ account หลายตัวพร้อมกัน (Batch account insights)
GET /api/v1/insights/accounts
รวมการอ่านของ dashboard ทั้งหน้าให้เหลือคำขอเดียว คือ account ที่เลือกสำหรับหน้าต่างปัจจุบัน และเลือกได้ว่าจะขอหน้าต่างเปรียบเทียบเพิ่มหรือไม่ การอนุญาตและการ gating ตาม freshness รายรายการเหมือน endpoint เดี่ยว รวมถึงการจัดคิว sync รายรายการ ไม่มีคำสั่ง CLI หรือ MCP tool สำหรับ endpoint นี้ Scopes: insight:read
Query parameters
| Name | Type | Required | Description |
|---|---|---|---|
| accountId | string | Yes | ตัวกรอง account แบบทำซ้ำได้, 1-25 ID |
| rangeStartUtc | string | No | ISO instant, จุดเริ่มหน้าต่างปัจจุบัน |
| rangeEndUtc | string | No | ISO instant, จุดสิ้นสุดหน้าต่างปัจจุบัน |
| previousRangeStartUtc | string | No | ISO instant, จุดเริ่มหน้าต่างเปรียบเทียบ ต้องเริ่มก่อนหน้าต่างปัจจุบัน |
| previousRangeEndUtc | string | No | ISO instant, จุดสิ้นสุดหน้าต่างเปรียบเทียบ |
คู่ start/end ทุกคู่ต้องส่งพร้อมกัน และแต่ละหน้าต่างกว้างได้สูงสุด 90 วัน
Request example
curl -sS "https://postkub.com/api/v1/insights/accounts?accountId=acc_example1&accountId=acc_example2&rangeStartUtc=2026-11-04T00:00:00.000Z&rangeEndUtc=2026-12-04T00:00:00.000Z&previousRangeStartUtc=2026-10-04T00:00:00.000Z&previousRangeEndUtc=2026-11-04T00:00:00.000Z" \
-H "Authorization: Bearer <API_KEY>"
Response 200 OK
{
"accounts": [
{
"accountId": "acc_example1",
"range": { "startUtc": "2026-11-04T00:00:00.000Z", "endUtc": "2026-12-04T00:00:00.000Z" },
"freshness": "fresh",
"lastSyncedAt": "2026-12-04T07:45:00.000Z",
"metrics": [
{ "name": "impressions", "value": 1200, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "reach", "value": 980, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "likes", "value": 154, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "comments", "value": 23, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "shares", "value": 12, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "saves", "value": null, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": "unsupported_by_provider" },
{ "name": "video_views", "value": 3100, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "profile_views", "value": 45, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "followers", "value": 1261, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null }
]
}
],
"previousAccounts": [
{
"accountId": "acc_example1",
"range": { "startUtc": "2026-10-04T00:00:00.000Z", "endUtc": "2026-11-04T00:00:00.000Z" },
"freshness": "fresh",
"lastSyncedAt": "2026-12-04T07:45:00.000Z",
"metrics": [
{ "name": "impressions", "value": 1105, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "reach", "value": 940, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "likes", "value": 149, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "comments", "value": 20, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "shares", "value": 9, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "saves", "value": null, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": "unsupported_by_provider" },
{ "name": "video_views", "value": 2870, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "profile_views", "value": 51, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "followers", "value": 1180, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null }
]
}
]
}
แต่ละรายการใน accounts และ previousAccounts มีรูปแบบเดียวกับ response ของ endpoint เดี่ยว โดย previousAccounts จะเป็นอาร์เรย์ว่างจนกว่าคุณจะส่งคู่ previousRange มา
| Status | Meaning |
|---|---|
| 200 | ได้รับ snapshot ราย account (อาจยังไม่สดใหม่) |
| 400 | Query ไม่ถูกต้อง: ช่วงเวลาผิด, ID เกิน 25 ตัว หรือคู่หน้าต่างไม่ครบ (ดู Errors) |
| 401 | ต้องยืนยันตัวตน |
| 403 | Key ไม่มี insight:read |
| 404 | account ที่ขอรายการใดรายการหนึ่งไม่พบหรืออยู่นอก scope ของ key |
อ่าน insights ของ post หลายโพสต์พร้อมกัน (Batch post insights)
GET /api/v1/insights/posts
รวมการอ่านตารางราย post ให้เหลือคำขอเดียว โดยการอนุญาตและการจัดคิว sync รายรายการเหมือน endpoint เดี่ยว ไม่มีคำสั่ง CLI หรือ MCP tool สำหรับ endpoint นี้ Scopes: insight:read
Query parameters
| Name | Type | Required | Description |
|---|---|---|---|
| postId | string | Yes | ตัวกรอง post แบบทำซ้ำได้, 1-25 ID |
| rangeStartUtc | string | No | ISO instant, จุดเริ่มหน้าต่างช่วง |
| rangeEndUtc | string | No | ISO instant, จุดสิ้นสุดหน้าต่างช่วง กว้างสุด 90 วัน |
Request example
curl -sS "https://postkub.com/api/v1/insights/posts?postId=post_example123&postId=post_example124" \
-H "Authorization: Bearer <API_KEY>"
Response 200 OK
{
"posts": [
{
"postId": "post_example123",
"range": { "startUtc": "2026-11-04T00:00:00.000Z", "endUtc": "2026-12-04T00:00:00.000Z" },
"targets": [
{
"socialAccountId": "acc_example1",
"freshness": "fresh",
"lastSyncedAt": "2026-12-04T07:45:00.000Z",
"metrics": [
{ "name": "impressions", "value": 540, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "reach", "value": 480, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "likes", "value": 61, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "comments", "value": 12, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "shares", "value": 4, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "saves", "value": null, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": "unsupported_by_provider" },
{ "name": "video_views", "value": 990, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "profile_views", "value": 8, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null },
{ "name": "followers", "value": 1261, "unit": "count", "asOf": "2026-12-04T07:45:00.000Z", "unavailableReason": null }
],
"unavailableReason": null
}
]
}
]
}
แต่ละรายการใน posts มีรูปแบบเดียวกับ response ของ endpoint เดี่ยว
| Status | Meaning |
|---|---|
| 200 | ได้รับ snapshot ราย post (อาจยังไม่สดใหม่) |
| 400 | Query ไม่ถูกต้อง: ช่วงเวลาผิดหรือ ID เกิน 25 ตัว (ดู Errors) |
| 401 | ต้องยืนยันตัวตน |
| 403 | Key ไม่มี insight:read |
| 404 | post ที่ขอรายการใดรายการหนึ่งไม่พบหรือไม่มี target account ที่เข้าถึงได้ |
ข้อมูลอนุกรมรายวัน (Daily metric series)
GET /api/v1/insights/metric-series
คืน snapshot metric รายวันที่บันทึกไว้สำหรับการวาดกราฟ โดยมีหนึ่งอนุกรมต่อ metric ที่ขอต่อหนึ่ง account metric เริ่มต้นคือ followers account ที่ยังไม่มีประวัติหรือประวัติเก่าจะถูกจัดคิว sync เพื่อ backfill ประวัติจาก provider ในจุดที่ provider เปิดเผย ส่วน provider ที่ไม่มีประวัติ metric ก็จะคืนผลลัพธ์ว่างต่อไป ไม่มีคำสั่ง CLI หรือ MCP tool สำหรับ endpoint นี้ Scopes: insight:read
Query parameters
| Name | Type | Required | Description |
|---|---|---|---|
| accountId | string | Yes | ตัวกรอง account แบบทำซ้ำได้, 1-25 ID |
| metric | string | No | ตัวกรอง metric แบบทำซ้ำได้, 1-6 ค่า เลือกจาก impressions, reach, likes, comments, shares, saves, video_views, profile_views, followers ค่าเริ่มต้น followers |
| rangeStartUtc | string | No | ISO instant, จุดเริ่มหน้าต่างช่วง |
| rangeEndUtc | string | No | ISO instant, จุดสิ้นสุดหน้าต่างช่วง กว้างสุด 90 วัน |
Request example
curl -sS "https://postkub.com/api/v1/insights/metric-series?accountId=acc_example1&metric=followers" \
-H "Authorization: Bearer <API_KEY>"
Response 200 OK
{
"range": { "startUtc": "2026-11-04T00:00:00.000Z", "endUtc": "2026-12-04T00:00:00.000Z" },
"accounts": [
{
"accountId": "acc_example1",
"freshness": "fresh",
"lastSyncedAt": "2026-12-04T07:45:00.000Z",
"series": [
{
"metric": "followers",
"points": [
{ "day": "2026-12-03", "value": 1250 },
{ "day": "2026-12-04", "value": 1261 }
]
}
]
}
]
}
day เป็นวันที่ปฏิทิน UTC ในรูปแบบ YYYY-MM-DD วันที่ sync ยังไม่ได้เติมจะไม่ปรากฏใน points เลย API ไม่แต่งค่าในวันที่ขาดหาย
| Status | Meaning |
|---|---|
| 200 | ได้รับอนุกรมรายวันราย account (อาจว่างสำหรับช่วงที่ยังไม่มีข้อมูล) |
| 400 | Query ไม่ถูกต้อง: ช่วงเวลาผิด, ID เกิน 25 ตัว, metric เกิน 6 ค่า หรือชื่อ metric ไม่รู้จัก (ดู Errors) |
| 401 | ต้องยืนยันตัวตน |
| 403 | Key ไม่มี insight:read |
| 404 | account ที่ขอรายการใดรายการหนึ่งไม่พบหรืออยู่นอก scope ของ key |
