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 状态代码

您只能删除没有任何下级组织部门或其分配用户的组织部门。在删除之前,您需要将用户重新分配给其他组织部门,并移除所有下级组织部门。