Members

สมาชิก · คำเชิญ · บทบาท

Members

จัดการสมาชิกของธุรกิจและบทบาทของแต่ละคน — ดูรายชื่อสมาชิก เปลี่ยนบทบาท นำสมาชิกออก และส่งหรือยกเลิกคำเชิญ ใช้ GET /roles เพื่อหาค่า roleId ที่ endpoint เหล่านี้ต้องใช้

Account key: ทุก request ด้านล่างต้องส่ง X-Business-Id: <business id> เพื่อเลือกธุรกิจที่จะทำงานด้วย (ถ้าไม่ส่งจะได้ 400 business_required) ส่วน business key จะไม่อ่าน header นี้ เพราะผูกกับธุรกิจเดียวอยู่แล้ว ดูเพิ่มที่ เริ่มต้นใช้งาน → API key ระดับบัญชี

GET /members

ดูรายชื่อสมาชิกของธุรกิจนี้

Scopes: manage_members

curl https://phone.mcloud.co.th/api/v1/members \
  -H "Authorization: Bearer crk_..."
{
  "members": [
    {
      "id": "0192b9...",
      "userId": "0192c1...",
      "name": "Somchai",
      "email": "[email protected]",
      "image": null,
      "roleId": "0192d4...",
      "roleKey": "owner",
      "roleName": "Owner",
      "joinedAt": "2026-01-12T03:20:00Z"
    }
  ]
}

PATCH /members/{id}

เปลี่ยนบทบาทของสมาชิก — {id} คือ id ของสมาชิก (ค่า id จาก GET /members ไม่ใช่ userId)

Scopes: manage_members

ParamTypeNote
roleIduuidrequired (จาก GET /roles)
ErrorStatusเมื่อไหร่
member_not_found404ไม่มีสมาชิก id นี้ในธุรกิจนี้
role_not_found404ไม่มี roleId นี้ในธุรกิจนี้
cannot_change_owner_role403สมาชิกคนนั้นเป็นเจ้าของ
use_transfer_ownership422ตั้งบทบาทเป็นเจ้าของผ่านทางนี้ไม่ได้ — ให้ใช้การโอนสิทธิ์เจ้าของแทน
curl -X PATCH https://phone.mcloud.co.th/api/v1/members/$ID \
  -H "Authorization: Bearer crk_..." \
  -H "Content-Type: application/json" \
  -d '{"roleId":"0192d4..."}'
{ "ok": true }

DELETE /members/{id}

นำสมาชิกออกจากธุรกิจนี้ — {id} คือ id ของสมาชิก

Scopes: manage_members

ErrorStatusเมื่อไหร่
cannot_remove_self422นำตัวเองออกจากธุรกิจไม่ได้
cannot_remove_owner403นำเจ้าของออกไม่ได้
{ "ok": true }

GET /members/invites

ดูคำเชิญที่ยังค้างอยู่ของธุรกิจนี้

Scopes: manage_members

{
  "invites": [
    {
      "id": "0192e7...",
      "email": "[email protected]",
      "roleId": "0192d4...",
      "expiresAt": "2026-06-16T00:00:00Z",
      "createdAt": "2026-06-09T00:00:00Z"
    }
  ]
}

POST /members/invites

เชิญคนเข้าธุรกิจนี้ — เลือกส่งอีเมลคำเชิญและภาษาของอีเมลได้

Scopes: manage_members

ParamTypeNote
emailstringrequired
roleIduuidrequired (จาก GET /roles)
sendEmailbooleanoptional — ส่งลิงก์คำเชิญทางอีเมล
language"th" | "en"optional — ภาษาของอีเมล
ErrorStatusเมื่อไหร่
role_not_found404ไม่มี roleId นี้ในธุรกิจนี้
already_member409อีเมลนั้นเป็นสมาชิกอยู่แล้ว
invite_already_pending409มีคำเชิญค้างอยู่สำหรับอีเมลนั้นแล้ว
curl -X POST https://phone.mcloud.co.th/api/v1/members/invites \
  -H "Authorization: Bearer crk_..." \
  -H "Content-Type: application/json" \
  -d '{"email":"[email protected]","roleId":"0192d4...","sendEmail":true,"language":"en"}'
{
  "id": "0192e7...",
  "link": "https://phone.mcloud.co.th/invite/abc123",
  "expiresAt": "2026-06-16T00:00:00Z",
  "emailStatus": "sent",
  "emailError": null
}

DELETE /members/invites/{id}

ยกเลิกคำเชิญที่ค้างอยู่ — {id} คือ id ของคำเชิญ

Scopes: manage_members

{ "ok": true }

GET /roles

ดูบทบาทที่มีในธุรกิจนี้ — ใช้ค่า id เหล่านี้กับ endpoint สมาชิกและคำเชิญด้านบน

Scopes: manage_members · manage_roles

curl https://phone.mcloud.co.th/api/v1/roles \
  -H "Authorization: Bearer crk_..."
{
  "roles": [
    { "id": "0192d4...", "key": "owner", "name": "Owner", "isSystem": true },
    { "id": "0192d5...", "key": "agent", "name": "Agent", "isSystem": false }
  ]
}