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 中的「frontline+sales」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 狀態碼

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