Directory API:组织部门

管理组织部门

Google Workspace 账号的组织树由多个组织单元组成,可让您以逻辑分层结构管理用户。这与 Google 管理控制台的“组织和用户”标签页中的功能类似。客户的组织部门层次结构不得超过 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",
}

JSON 响应

成功的响应会返回 HTTP 201 状态代码。除了状态代码以外,响应还会返回新群组的属性:

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

更新组织部门

如需更新组织部门,请使用以下 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"
}

如果用户账号在创建时未分配给特定组织部门,则该账号位于顶级组织部门中。用户所属的组织部门决定了用户可以访问哪些 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"
}

检索组织部门

如需检索组织部门下的所有子组织部门、组织部门下的直接子组织部门,或所有子组织部门加上指定的组织部门,请使用以下 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"
     },
     {
    "kind": "directory#orgUnit",
    "name": "frontline sales",
    "description": "The frontline sales team",
    "orgUnitPath": "/corp/sales/frontline sales",
    "parentOrgUnitPath": "/corp/sales"
     },
     {
    "kind": "directory#orgUnit",
    "name": "support",
    "description": "The corporate support team",
    "orgUnitPath": "/corp/support",
    "parentOrgUnitPath": "/corp"
     },
     {
    "kind": "directory#orgUnit",
    "name": "sales_support",
    "description": "The BEST support team",
    "orgUnitPath": "/corp/support/sales_support",
    "parentOrgUnitPath": "/corp/support"
     }
  ]
  }

删除组织部门

如需删除组织部门,请使用以下 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 状态代码

您只能删除不包含任何下级组织部门或未分配任何用户的组织部门。您需要先将用户重新分配给其他组织部门,并移除所有下级组织部门,然后才能删除组织部门。