Skip to main content

Peep OA — Public API Documentation

Overview

Public API สำหรับให้ภายนอก (3rd-party) เชื่อมต่อกับระบบ Peep Official Account เพื่อส่งข้อความไปหาผู้ใช้ผ่าน OA

Base URL:

https://oa-api.peepshare.ai

Postman Collection: Download — Import เข้า Postman เพื่อทดสอบ API ได้ทันที


Table of Contents


Authentication

Public API ใช้ระบบ API Key + JWT Token

ขั้นตอน:

  1. ได้รับ api_key และ api_secret จากทีม admin
  2. เรียก POST /api/v2/public/auth/token เพื่อรับ access_token และ refresh_token
  3. ใส่ access_token ใน Header ทุก request:
    Authorization: Bearer <access_token>
  4. เมื่อ token หมดอายุ ใช้ POST /api/v2/public/auth/refresh-token เพื่อขอ token ใหม่

Rate Limiting

Endpoint GroupLimit
ทุก endpoint200 requests / นาที

เมื่อเกิน rate limit จะได้ HTTP 429 Too Many Requests:

{
"statusCode": 429,
"data": "ThrottlerException: Too Many Requests",
"timestamp": "2026-07-22 17:23:30",
"path": "/api/v2/public/webhook/broadcast-greeting"
}

Response Format

Success Response

ทุก response สำเร็จจะถูก wrap ด้วย data field:

{
"data": { ... }
}

Error Response

เมื่อเกิด error จะมีรูปแบบ:

{
"statusCode": 404,
"data": {
"statusCode": 404,
"code": "NOT_FOUND",
"info": "not found account_provider in db"
},
"timestamp": "2026-07-22 15:46:10",
"path": "/api/v2/public/webhook/broadcast-greeting"
}
FieldTypeDescription
statusCodenumberHTTP status code
data.codestringError code (ดูตารางด้านล่าง)
data.infostringรายละเอียด error
timestampstringเวลาที่เกิด error
pathstringEndpoint ที่เรียก

Error Codes:

CodeHTTP Statusคำอธิบาย
UNAUTHORIZED401Token ไม่ถูกต้องหรือหมดอายุ
NOT_FOUND404ไม่พบข้อมูลที่ร้องขอ
BAD_REQUEST400ข้อมูลไม่ถูกต้อง
JOB_BUSY400มี broadcast job กำลังทำงานอยู่
INTERNAL_SERVER_ERROR500ข้อผิดพลาดภายในระบบ

Endpoints


1. Generate Token

สร้าง access token สำหรับเรียก API

POST /api/v2/public/auth/token

Authentication: ไม่ต้อง (ใช้ api_key + api_secret แทน)

Request Body:

FieldTypeRequiredDescription
api_keystringAPI Key ที่ได้รับ
api_secretstringAPI Secret ที่ได้รับ

Example Request:

curl -X POST https://<domain>/api/v2/public/auth/token \
-H "Content-Type: application/json" \
-d '{
"api_key": "pk_abc123...",
"api_secret": "sk_xyz789..."
}'

Example Response:

{
"data": {
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"refresh_token": "eyJhbGciOiJIUzI1NiIs...",
"token_type": "Bearer",
"expires_in": "1h"
}
}

2. Refresh Token

ขอ access token ใหม่เมื่อ token หมดอายุ

POST /api/v2/public/auth/refresh-token

Authentication: ไม่ต้อง

Request Body:

FieldTypeRequiredDescription
refresh_tokenstringRefresh token ที่ได้จาก Generate Token

Example Request:

curl -X POST https://<domain>/api/v2/public/auth/refresh-token \
-H "Content-Type: application/json" \
-d '{
"refresh_token": "eyJhbGciOiJIUzI1NiIs..."
}'

Example Response:

{
"data": {
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"refresh_token": "eyJhbGciOiJIUzI1NiIs...",
"token_type": "Bearer",
"expires_in": "1h"
}
}

3. Broadcast Greeting

ส่ง greeting message (ข้อความต้อนรับที่ตั้งค่าไว้ใน OA) ไปหา user

POST /api/v2/public/webhook/broadcast-greeting

Authentication: Bearer Token

Request Body:

FieldTypeRequiredDescription
user_idstringUser ID ของผู้รับ

Example Request:

curl -X POST https://<domain>/api/v2/public/webhook/broadcast-greeting \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{
"user_id": "user_123456"
}'

Example Response:

{
"data": {
"id": "uuid-of-greeting",
"title": "Welcome Message",
"slug": "welcome-message",
"data": [
{
"type": "message",
"msg": "สวัสดีครับ ยินดีต้อนรับ!"
}
]
}
}

ส่งรูปภาพไปหา user โดย link ใส่หรือไม่ใส่ก็ได้ — ถ้าใส่จะฝัง link ลงไปในรูป (กดที่รูปแล้วเปิด URL) ถ้าไม่ใส่จะเป็นรูปภาพธรรมดา

POST /api/v2/public/webhook/broadcast-image-link

Authentication: Bearer Token

Request Body:

FieldTypeRequiredDescription
user_idstringUser ID ของผู้รับ
image_urlstringURL ของรูปภาพ
linkstringURL ที่ฝังในรูป (ถ้าใส่ = กดรูปแล้วเปิด link, ถ้าไม่ใส่ = รูปธรรมดา)

Example Request:

curl -X POST https://<domain>/api/v2/public/webhook/broadcast-image-link \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{
"user_id": "user_123456",
"image_url": "https://images.unsplash.com/photo-1564760290292-23341e4df6ec?q=80&w=1740&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
"link": "https://example.com/landing-page"
}'

Example Response:

{
"data": "success"
}

5. Broadcast Message (Single User)

ส่งข้อความ text ไปหา user คนเดียว

POST /api/v2/public/webhook/broadcast-message

Authentication: Bearer Token

Request Body:

FieldTypeRequiredDescription
user_idstringUser ID ของผู้รับ
msgstringเนื้อหาข้อความหลัก
descstringข้อความเล็กที่แสดงบน push notification

Example Request:

curl -X POST https://<domain>/api/v2/public/webhook/broadcast-message \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{
"user_id": "user_123456",
"msg": "สวัสดีครับ คุณมีข้อความใหม่",
"desc": "แจ้งเตือน"
}'

Example Response:

{
"data": "success"
}

6. Broadcast Message (Mass)

Broadcast ข้อความไปหาผู้ใช้หลายคน หรือทุกคน

POST /api/v2/public/message/broadcast-message

Authentication: Bearer Token

Request Body:

FieldTypeRequiredDescription
targetstringประเภทการส่ง: all, selected, single
user_idsstring[]❌*รายการ User IDs (*จำเป็นเมื่อ target = selected หรือ single)
itemsarrayรายการข้อความ (สูงสุด 5 items)

Item Object:

FieldTypeRequiredDescription
typestringประเภทข้อความ (ดู Message Item Types)
msgstring | string[]เนื้อหาข้อความ
descstringคำอธิบาย (สูงสุด 170 ตัวอักษร)
linkstringURL link (สำหรับ type = oa_image_link)

Example Request — type message (ข้อความ text):

curl -X POST https://<domain>/api/v2/public/message/broadcast-message \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{
"target": "selected",
"user_ids": ["user_001", "user_002", "user_003"],
"items": [
{
"type": "message",
"msg": "สวัสดีครับ นี่คือข้อความ broadcast",
"desc": "ข้อความเล็กบน push notification"
}
]
}'

Example Request — type oa_image_link (รูปภาพพร้อม link):

curl -X POST https://<domain>/api/v2/public/message/broadcast-message \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{
"target": "all",
"items": [
{
"type": "oa_image_link",
"msg": "https://images.unsplash.com/photo-1564760290292-23341e4df6ec?q=80&w=1740&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
"link": "https://example.com/promo",
"desc": "โปรโมชั่นพิเศษวันนี้"
}
]
}'

Example Request — type image (รูปภาพธรรมดา ไม่มี link):

curl -X POST https://<domain>/api/v2/public/message/broadcast-message \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{
"target": "single",
"user_ids": ["user_001"],
"items": [
{
"type": "image",
"msg": "https://images.unsplash.com/photo-1564760290292-23341e4df6ec?q=80&w=1740&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
}
]
}'

Example Request — type flex (flex message):

curl -X POST https://<domain>/api/v2/public/message/broadcast-message \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{
"target": "selected",
"user_ids": ["user_001"],
"items": [
{
"type": "flex",
"msg": "{\"type\":\"bubble\",\"hero\":{\"type\":\"image\",\"url\":\"https://developers-resource.landpress.line.me/fx/img/01_1_cafe.png\",\"size\":\"full\",\"aspectRatio\":\"20:13\",\"aspectMode\":\"cover\",\"action\":{\"type\":\"uri\",\"uri\":\"https://line.me/\"}},\"body\":{\"type\":\"box\",\"layout\":\"vertical\",\"contents\":[{\"type\":\"text\",\"text\":\"Brown Cafe\",\"weight\":\"bold\",\"size\":\"xl\"},{\"type\":\"box\",\"layout\":\"vertical\",\"margin\":\"lg\",\"spacing\":\"sm\",\"contents\":[{\"type\":\"box\",\"layout\":\"baseline\",\"spacing\":\"sm\",\"contents\":[{\"type\":\"text\",\"text\":\"Place\",\"color\":\"#aaaaaa\",\"size\":\"sm\",\"flex\":1},{\"type\":\"text\",\"text\":\"Flex Tower, 7-7-4 Midori-ku, Tokyo\",\"wrap\":true,\"color\":\"#666666\",\"size\":\"sm\",\"flex\":5}]},{\"type\":\"box\",\"layout\":\"baseline\",\"spacing\":\"sm\",\"contents\":[{\"type\":\"text\",\"text\":\"Time\",\"color\":\"#aaaaaa\",\"size\":\"sm\",\"flex\":1},{\"type\":\"text\",\"text\":\"10:00 - 23:00\",\"wrap\":true,\"color\":\"#666666\",\"size\":\"sm\",\"flex\":5}]}]}]},\"footer\":{\"type\":\"box\",\"layout\":\"vertical\",\"spacing\":\"sm\",\"contents\":[{\"type\":\"button\",\"style\":\"link\",\"height\":\"sm\",\"action\":{\"type\":\"uri\",\"label\":\"CALL\",\"uri\":\"https://line.me/\"}},{\"type\":\"button\",\"style\":\"link\",\"height\":\"sm\",\"action\":{\"type\":\"uri\",\"label\":\"WEBSITE\",\"uri\":\"https://line.me/\"}},{\"type\":\"box\",\"layout\":\"vertical\",\"contents\":[],\"margin\":\"sm\"}],\"flex\":0}}",
"desc": "Brown Cafe"
}
]
}'

Example Response:

{
"data": {
"id": "broadcast-uuid",
"data": [
{
"type": "message",
"msg": "สวัสดีครับ นี่คือข้อความ broadcast"
}
],
"broadcast_at": "2025-07-22 10:30:00",
"created_at": "2025-07-22 10:30:00",
"estimate_time_detail": {
"total_job_time_minutes": 2
}
}
}

7. Broadcast Group Message

Broadcast ข้อความไปหาสมาชิกทั้งหมดในกลุ่ม

POST /api/v2/public/message/broadcast-group-message

Authentication: Bearer Token

Request Body:

FieldTypeRequiredDescription
account_provider_group_idstringUUID ของกลุ่มที่ต้องการส่ง
itemsarrayรายการข้อความ (สูงสุด 5 items, รูปแบบเดียวกับ Item Object)

Example Request:

curl -X POST https://<domain>/api/v2/public/message/broadcast-group-message \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{
"account_provider_group_id": "group-uuid-abc123",
"items": [
{
"type": "message",
"msg": "ข้อความถึงสมาชิกในกลุ่ม"
},
{
"type": "oa_image_link",
"msg": "https://example.com/event.jpg",
"link": "https://example.com/event",
"desc": "งาน Event สุดพิเศษ"
}
]
}'

Example Response:

{
"data": {
"id": "broadcast-uuid",
"data": [...],
"broadcast_at": "2025-07-22 10:30:00",
"created_at": "2025-07-22 10:30:00",
"estimate_time_detail": {
"total_job_time_minutes": 1
}
}
}

8. Broadcast Member Session

Broadcast ข้อความไปหาสมาชิกใน member group broadcast session

POST /api/v2/public/message/broadcast-member-session

Authentication: Bearer Token

Request Body:

FieldTypeRequiredDescription
member_group_broadcast_idstringUUID ของ member group broadcast
itemsarrayรายการข้อความ (สูงสุด 5 items, รูปแบบเดียวกับ Item Object)

Example Request:

curl -X POST https://<domain>/api/v2/public/message/broadcast-member-session \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{
"member_group_broadcast_id": "mgb-uuid-xyz789",
"items": [
{
"type": "message",
"msg": "ข้อความสำหรับ member session"
}
]
}'

Example Response:

{
"data": {
"id": "broadcast-uuid",
"data": [...],
"broadcast_at": "2025-07-22 10:30:00",
"created_at": "2025-07-22 10:30:00",
"estimate_time_detail": {
"total_job_time_minutes": 3
}
}
}

Message Item Types

TypeDescriptionmsg Formatต้องมี link?
messageข้อความ text ธรรมดาstring
oa_image_linkรูปภาพที่กดแล้วเปิด linkstring (URL รูป)
imageรูปภาพธรรมดา (ไม่มี link)string (URL รูป)
flexFlex messagestring (JSON format)

Quick Start

# 1. ขอ token
TOKEN=$(curl -s -X POST https://<domain>/api/v2/public/auth/token \
-H "Content-Type: application/json" \
-d '{"api_key":"pk_...","api_secret":"sk_..."}' | jq -r '.data.access_token')

# 2. ส่งข้อความไปหา user
curl -X POST https://<domain>/api/v2/public/webhook/broadcast-message \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"user_id": "target_user_id",
"msg": "Hello from API!"
}'

# 3. Broadcast ไปหาทุกคน
curl -X POST https://<domain>/api/v2/public/message/broadcast-message \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"target": "all",
"items": [{"type": "message", "msg": "📢 ประกาศสำคัญ!"}]
}'