Directory API:機構單位

透過集合功能整理內容 你可以依據偏好儲存及分類內容。

管理機構單位

Google Workspace 帳戶的機構樹狀結構是由機構單位組成,可讓您以邏輯和階層結構的方式管理使用者。這與管理控制台和「功能使用者」中的功能類似。客戶的機構單位階層數量上限為 35 層。詳情請參閱管理員說明中心

  • Google Workspace 帳戶只有一個機構樹狀結構。初始設定帳戶時,這個帳戶在帳戶層級已設定機構單位。這是與主網域相關聯的機構。如要進一步瞭解主網域,請參閱 API 限制資訊
  • 機構單位的路徑不得重複。機構單位名稱在機構階層中可能不相同,但其與所屬機構單位中的名稱不得重複。而機構單位的名稱則不區分大小寫。
  • 機構單位會沿用機構階層的政策。所有機構單位都能封鎖這個上層繼承。各項政策的優先順序比其他機構單位優先。這表示下層機構單位的政策可能高於上層機構單位的政策。
  • 機構單位可上下移動。此外,在填入新的機構,或是將部分使用者從某個機構單位移至另一個機構單位時,關聯機構的使用者可以一併移動或批次移動。
  • 機構單位資源中保留的資料會持續變更。提出要求時,實體傳回的屬性保證會在擷取實體時保持一致。也就是說,您不會看到「部分」更新。如果擷取作業傳回多個實體,則實體之間就不一致。如果回應橫跨分頁的多個頁面,這種做法尤其實用。

建立機構單位

如要建立機構單位,請使用下列 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 回應

在以下範例中,系統會擷取「#19;frontline sales'」機構單位。請留意 'frontline+sales' 要求 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

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

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

get 查詢字串會傳回 orgUnitPath 下的 all 子機構單位,或是傳回 orgUnitPath 的立即 children。預設為 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 狀態碼

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