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 响应

在下例中,检索了一线员工版组织部门。请注意请求 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 请求删除了以下组织部门的后端测试:
DELETE https://admin.googleapis.com/admin/directory/v1/customer/C03az79cb/orgunits/corp/sales/backend_tests

成功的响应将返回一个 HTTP 200 状态代码

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