Businesses

Account key · จัดการธุรกิจ

Businesses

สร้างและจัดการธุรกิจที่บัญชีเป็นเจ้าของ — ธุรกิจคือ tenant ระดับบนสุด สาย สมาชิก คอลเลกชัน และการเชื่อมต่อทั้งหมดอยู่ภายในธุรกิจ

Account key เท่านั้น — endpoint เหล่านี้ใช้กับ business key ไม่ได้ (business key ผูกกับธุรกิจเดียว) ถ้าเรียกด้วย business key จะได้ 403 account_key_required และ account key ไม่ต้องส่ง X-Business-Id ที่นี่ เพราะ path {id} ระบุธุรกิจอยู่แล้ว ดูเพิ่มที่ เริ่มต้นใช้งาน → API key ระดับบัญชี

GET /businesses

ดูทุกธุรกิจที่เจ้าของบัญชีเป็นสมาชิก

Scopes: account key เท่านั้น (manage_all)

curl https://phone.mcloud.co.th/api/v1/businesses \
  -H "Authorization: Bearer crk_..."
{
  "items": [
    { "id": "0192b9...", "name": "Acme Co.", "slug": "acme-co" }
  ],
  "total": 1
}

POST /businesses

สร้างธุรกิจใหม่ — ผู้เรียกจะเป็นเจ้าของธุรกิจนั้น

Scopes: account key เท่านั้น (manage_all)

ParamTypeNote
namestring (2-80)required
curl -X POST https://phone.mcloud.co.th/api/v1/businesses \
  -H "Authorization: Bearer crk_..." \
  -H "Content-Type: application/json" \
  -d '{"name":"Acme Co."}'
{ "id": "0192b9...", "name": "Acme Co.", "slug": "acme-co" }

GET /businesses/{id}

ดึงธุรกิจที่เจ้าของบัญชีเป็นสมาชิก พร้อม roleKey ของเจ้าของบัญชีในธุรกิจนั้น

Scopes: account key เท่านั้น (manage_all)

ได้ 404 not_found ถ้าเจ้าของบัญชีไม่ใช่สมาชิกของธุรกิจนั้น

{ "id": "0192b9...", "name": "Acme Co.", "slug": "acme-co", "roleKey": "owner" }

PATCH /businesses/{id}

เปลี่ยนชื่อธุรกิจ

Scopes: account key เท่านั้น (manage_all)

ParamTypeNote
namestring (2-80)required
curl -X PATCH https://phone.mcloud.co.th/api/v1/businesses/$ID \
  -H "Authorization: Bearer crk_..." \
  -H "Content-Type: application/json" \
  -d '{"name":"Acme Co. (renamed)"}'
{ "id": "0192b9...", "name": "Acme Co. (renamed)", "slug": "acme-co" }

DELETE /businesses/{id}

ย้ายธุรกิจลงถังขยะ (soft delete) — เฉพาะเจ้าของ ถ้าบทบาทของผู้เรียกในธุรกิจนั้นไม่ใช่ owner จะได้ 403 owner_required ธุรกิจจะถูกซ่อนจากทุกที่ทันที (สมาชิกเข้าไม่ได้ · API key ของธุรกิจนี้หยุดทำงาน) แต่ ยังกู้คืนได้ — ข้อมูลจะถูกลบถาวรก็ต่อเมื่อแอดมินของแพลตฟอร์มสั่งลบถาวรจากหน้าถังขยะเท่านั้น

Scopes: account key เท่านั้น (manage_all) และต้องมีบทบาทเจ้าของ

curl -X DELETE https://phone.mcloud.co.th/api/v1/businesses/$ID \
  -H "Authorization: Bearer crk_..."
{ "ok": true, "id": "0192b9..." }