Directory API:機構單位

管理機構單位

Google Workspace 帳戶的機構樹狀結構由機構單位組成,可讓您以有邏輯的階層結構管理使用者。這類似於管理控制台的「機構與使用者」所提供的功能分頁。客戶的機構單位階層最多只能有 35 層。如需更多資訊,請參閱管理員說明中心

  • Google Workspace 帳戶只能有一個機構樹狀結構。完成這個帳戶的初始設定時,該帳戶在帳戶層級設有機構單位。這是指與主網域相關聯的機構。如要進一步瞭解主網域,請參閱 API 限制資訊
  • 機構單位的路徑名稱沒有重複。機構單位名稱在機構階層中不能重複,但其名稱在同層級的機構單位中是獨一無二的。且機構單位名稱不區分大小寫。
  • 機構單位會沿用機構階層的政策。任何機構 單元可以覆寫繼承的政策,封鎖這個家長狀態鏈結。 政策的優先順序是由最接近的機構單位決定。 也就是說,子機構單位的政策優先順序高於 上層單元 blockInheritance 設定允許封鎖設定沿用機制: 機構單位及其子機構blockInheritance 已淘汰, 系統不再支援設為 `true`,且可能會產生非預期的結果。適用對象 如要進一步瞭解機構架構中的沿用機制和使用者,請參閱 管理員說明中心
  • 機構單位可向上或向下移動階層的樹狀結構。此外,填入新機構或將部分使用者從某個機構單位移至另一個機構單位時,可以將該機構的關聯使用者個別或批次移動。
  • 機構單位資源中儲存的資料可能會不斷變動。提出要求時,系統會保證針對實體傳回的屬性,在擷取實體時保持一致。也就是說,您不會看到「部分」更新。如果擷取作業傳回多個實體,您就不能保證各實體之間的一致性。當回應橫跨多個分頁時,更會如此。

建立機構單位

如要建立機構單位,請使用下列 POST 要求,並加入「授權要求」中所述的授權。

如果您是要建立機構單位的管理員,請使用 my_customer

POST https://admin.googleapis.com/admin/directory/v1/customer/my_customer/orgunits

如果您要為經銷商客戶建立機構單位,請使用 customerId。如要擷取 customerId,請使用「擷取使用者」作業。

POST https://admin.googleapis.com/admin/directory/v1/customer/customerId/orgunits

如要瞭解帳戶的機構架構,請參閱管理員說明中心。如需要求和回應屬性,請參閱 API 參考資料

JSON 要求

以下 JSON 經銷商範例顯示建立 sales_support 機構單位的要求主體範例。nameparentOrgUnitPath 是必填欄位:

POST https://admin.googleapis.com/admin/directory/v1/customer/C03az79cb/orgunits
{
    "name": "sales_support",
    "description": "The sales support team",
    "parentOrgUnitPath": "/corp/support",
    "blockInheritance": false
}

JSON 回應

成功的回應會傳回 HTTP 201 狀態碼。除了狀態碼之外,回應會傳回新群組的屬性:

{
    "kind": "directory#orgUnit",
    "name": "sales_support",
    "description": "The sales support team",
    "orgUnitPath": "/corp/support/sales_support",
    "parentOrgUnitPath": "/corp/support",
    "blockInheritance": false
  }

更新機構單位

如要更新機構單位,請使用下列 PUT 要求,並加入「授權要求」中所述的授權。如需要求和回應屬性,請參閱 API 參考資料

如果您是負責更新機構單位的管理員,請使用 my_customer

 PUT https://admin.googleapis.com/admin/directory/v1/customer/my_customer/orgunits/orgUnitPath

如果您是經銷商來為經銷商客戶更新機構單位,請使用 customerId。如要取得 customerId,請使用「擷取使用者」作業。

PUT https://admin.googleapis.com/admin/directory/v1/customer/customerId/orgunits/orgUnitPath
敬上

JSON 要求

下方範例已更新機構單位說明:

PUT https://admin.googleapis.com/admin/directory/v1/customer/my_customer/orgunits/corp/support/sales_support
{
    "description": "The BEST sales support team"
}

更新要求注意事項:

  • 你只需要在要求中提交更新的資訊。您無須在要求中輸入群組的所有屬性。
  • 如果使用者在建立使用者帳戶時未獲指派至特定機構單位,則該帳戶會屬於頂層機構單位。
  • 如要將機構單位移至帳戶機構架構的其他部分,請在要求中設定 parentOrgUnitPath 屬性。請特別注意,移動機構單位後,這些機構單位使用者的服務和設定可能會變更。

JSON 回應

成功的回應會傳回 HTTP 201 狀態碼。除了狀態碼,回應也會傳回已更新機構單位的屬性。

{
    "kind": "directory#orgUnit",
    "name": "sales_support",
    "description": "The BEST sales support team",
    "orgUnitPath": "/corp/support/sales_support",
    "parentOrgUnitPath": "/corp/support",
    "blockInheritance": false
}

如果使用者在建立使用者帳戶時未獲指派至特定機構單位,則該帳戶會屬於頂層機構單位。使用者可用的 Google Workspace 服務取決於所屬的機構單位。如果使用者移至新機構,存取權也會隨之變更。如要進一步瞭解機構架構,請參閱管理說明中心。如要進一步瞭解如何將使用者移至其他機構,請參閱「更新使用者」。

擷取機構單位

如要擷取機構單位,請使用下列 GET 要求,並加入「授權要求」中所述的授權。orgUnitPath 查詢字串是這個機構單位的完整路徑。如需要求和回應屬性,請參閱 API 參考資料

如果您是負責擷取機構單位的管理員,請使用 my_customer

GET https://admin.googleapis.com/admin/directory/v1/customer/my_customer/orgunits/orgUnitPath

如果您是經銷商,為經銷商客戶擷取機構單位,請使用 customerId。如要取得 customerId,請使用「擷取使用者」作業。

GET https://admin.googleapis.com/admin/directory/v1/customer/customerId/orgunits/orgUnitPath

JSON 回應

在下方範例中,「第一線銷售」已擷取機構單位資料。註明「第一線+銷售人員」要求 URI 中的 HTTP 編碼:

GET https://admin.googleapis.com/admin/directory/v1/customer/my_customer/orgunits/corp/sales/frontline+sales

成功的回應會傳回 HTTP 200 狀態碼。除了狀態碼,回應也會傳回機構單位設定:

{
    "kind": "directory#orgUnit",
    "name": "frontline sales",
    "description": "The frontline sales team",
    "orgUnitPath": "/corp/sales/frontline sales",
    "parentOrgUnitPath": "/corp/sales",
    "blockInheritance": false
}

擷取機構單位

如要擷取機構單位下的所有子機構單位、機構單位下的所有子機構單位,或是所有子機構單位加上指定機構單位的子機構單位,請使用以下 GET 要求,並加入授權要求中所述的授權。如需要求和回應屬性的相關資訊,請參閱 API 參考資料

如果您是帳戶管理員,會擷取所有子機構單位,請使用 my_customer。為了方便閱讀,這個範例使用了一行回傳:

GET https://admin.googleapis.com/admin/directory/v1/customer/my_customer
/orgunits?orgUnitPath=full org unit path&type=all or children or all_including_parent

如果您是為經銷商客戶擷取機構單位,請使用 customerId。如要取得 customerId,請使用「擷取使用者」作業:

GET https://admin.googleapis.com/admin/directory/v1/customer/customerId
/orgunits?orgUnitPath=full org unit path&type=all or children or all_including_parent

get 查詢字串會傳回 orgUnitPath 之下的 all 個子機構單位、orgUnitPath 的緊接 children 或所有子機構單位,以及為 all_including_parent 指定的 orgUnitPath。預設為 type=children

JSON 回應

舉例來說,這項要求會傳回以下機構單位開始的所有機構單位:/corp

GET https://admin.googleapis.com/admin/directory/v1/customer/my_customer/orgunits?orgUnitPath=/corp&type=all

成功的回應會傳回 HTTP 200 狀態碼。除了狀態碼,回應也會傳回帳戶的機構單位:

{
"kind": "directory#orgUnits",
    "organizationUnits": [
     {
    "kind": "directory#orgUnit",
    "name": "sales",
    "description": "The corporate sales team",
    "orgUnitPath": "/corp/sales",
    "parentOrgUnitPath": "/corp",
    "blockInheritance": false
     },
     {
    "kind": "directory#orgUnit",
    "name": "frontline sales",
    "description": "The frontline sales team",
    "orgUnitPath": "/corp/sales/frontline sales",
    "parentOrgUnitPath": "/corp/sales",
    "blockInheritance": false
     },
     {
    "kind": "directory#orgUnit",
    "name": "support",
    "description": "The corporate support team",
    "orgUnitPath": "/corp/support",
    "parentOrgUnitPath": "/corp",
    "blockInheritance": false
     },
     {
    "kind": "directory#orgUnit",
    "name": "sales_support",
    "description": "The BEST support team",
    "orgUnitPath": "/corp/support/sales_support",
    "parentOrgUnitPath": "/corp/support",
    "blockInheritance": false
     }
  ]
  }

刪除機構單位

如要刪除機構單位,請使用下列 DELETE 要求,並加入「授權要求」中所述的授權。如要擷取 customerId,請使用「擷取使用者」作業。如需要求和回應屬性,請參閱 API 參考資料

如果您是帳戶管理員刪除機構單位,請使用 my_customer

DELETE https://admin.googleapis.com/admin/directory/v1/customer/my_customer/orgunits/orgUnitPath

如果您是經銷商,為經銷商客戶刪除機構單位,請使用 customerId。如要取得 customerId,請使用「擷取使用者」作業。

DELETE https://admin.googleapis.com/admin/directory/v1/customer/customerId/orgunits/orgUnitPath
敬上 舉例來說,如果這位經銷商管理員的 DELETE 要求會刪除「backend_tests」機構單位:
DELETE https://admin.googleapis.com/admin/directory/v1/customer/C03az79cb/orgunits/corp/sales/backend_tests

成功的回應會傳回 HTTP 200 狀態碼

您只能刪除沒有任何子機構單位或指派給任何使用者的機構單位。刪除前,您必須先將使用者重新指派給其他機構單位,並移除所有子機構單位。