Enterprise License Manager API:开发者指南

本文档介绍了帐号级管理员和转销商管理员如何使用 Enterprise License Manager API 管理用户的许可分配。启用您帐号的产品 SKU 许可并创建用户后,您可以使用 Enterprise License Manager API 为帐号用户分配、更新、检索和删除许可。

在此版本中,企业许可管理器 API 供账号管理员和转销商管理员使用。拥有 License Management 权限的委派管理员也可以使用 Enterprise License Manager API。

注意:Enterprise License Manager API 由 Google 客户使用。如需了解 Google 第三方应用开发者如何管理许可,请参阅 Google Workspace Marketplace API

Enterprise License Manager API 基于网络服务的表征状态传输 (RESTful) 设计方法。

管理许可

分配许可

在执行此操作之前,客户或转销商已订购 Google 产品许可并创建用户。要将其中一项产品许可分配给此用户,请使用以下 POST HTTP 请求。添加 Authorization 标头,如向请求授权中所述。如需了解产品和 SKU ID,请参阅 API 的可用产品和 SKU

POST https://www.googleapis.com/apps/licensing/v1/product/productId/sku/skuId/user

注意:您可以为用户分配各种 Google 产品的许可。但是,同一用户一次只能为每件商品分配 1 个 SKU 许可。通过使用 API,可以将用户的 SKU 许可重新分配给产品中的其他 SKU 许可。

以下示例将 Google-Drive-storage-20GB SKU 分配给了主电子邮件地址为 alex@example.com 的用户:

POST https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-20GB/user

JSON 请求正文:

{
  "userId" : "alex@example.com",
}

成功的响应会返回 200 HTTP 状态代码。如需了解可能的错误代码,请参阅 API 的错误代码。如果成功,响应会以 JSON 数据格式返回许可分配状态。

JSON 响应

{
  "kind": "licensing#licenseAssignment",
  "etags": "etag value",
  "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-20GB/user/alex@example.com",
  "userId": "alex@example.com",
  "productId": "Google-Drive-storage",
  "skuId": "Google-Drive-storage-20GB",
  "skuName": "Google Drive storage 20 GB",
  "productName": "Google Drive storage"
}

如需了解详情,请参阅 licensesAssignments insert 方法参考页面。

使用同一产品的不同 SKU 重新分配用户的产品 SKU

如需将用户的许可重新分配给同一产品中的新许可 SKU,请使用以下 PUT HTTP 请求。该 API 还支持补丁语法。添加 Authorization 标头,如向请求授权中所述。如需了解产品和 SKU ID,请参阅 API 的可用产品和 SKU

PUT https://www.googleapis.com/apps/licensing/v1/product/productId/sku/the current skuId/user/user's email

本示例将当前的 20GB Google 云端硬盘存储空间 SKU 更新为 50GB Google 云端硬盘存储空间。当前许可 SKU 位于请求的 URI 中,新的许可 SKU 位于请求正文中:

PUT https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-20GB/user/alex@example.com

JSON 请求正文包含:

{
  "kind": "licensing#licenseAssignment",
  "etags": "etag value",
  "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-50GB/user/alex@example.com",
  "userId": "alex@example.com",
  "productId": "Google-Drive-storage",
  "skuId": "Google-Drive-storage-50GB",
  "skuName": "Google Drive storage 50 GB",
  "productName": "Google Drive storage"
}

成功的响应会返回 200 HTTP 状态代码。如需了解可能的错误代码,请参阅 API 的错误代码。如果成功,响应会以 JSON 数据格式返回许可分配状态。

JSON 响应

{
  "kind": "licensing#licenseAssignment",
  "etags": "etag value",
  "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-50GB/user/alex@example.com",
  "userId": "alex@example.com",
  "productId": "Google-Drive-storage",
  "skuId": "Google-Drive-storage-50GB",
  "skuName": "Google Drive storage 50 GB",
  "productName": "Google Drive storage"
}

如需了解详情,请参阅 licensesAssignments 更新方法patch 方法参考页面。

检索已获特定产品许可的所有用户

如需获取特定产品的所有用户许可,请使用以下 GET HTTP 请求。添加 Authorization 标头,如向请求授权中所述。customerId 查询字符串是客户的主域名。maxResults 查询字符串决定了 API 响应中返回的用户许可条目数量:

GET https://www.googleapis.com/apps/licensing/v1/product/productId/users?customerId=primary domain name&maxResults=max results per page

如需了解产品和 SKU ID,请参阅 API 的可用产品和 SKU

以下示例列出了 example.com 网域中拥有 Google 云端硬盘存储空间产品许可的所有用户搜索结果的第一页:

GET https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/users?customerId=example.com&maxResults=2

成功的响应会返回 200 HTTP 状态代码。如需了解可能的错误代码,请参阅 API 的错误代码。如果成功,响应将返回 JSON 格式的许可列表。

JSON 响应

{
  "kind" : "licensing#licenseAssignmentList",
  "etag": "etag value",
  "nextPageToken" : "the next page token value",
  "items": [
  {
    "kind": "licensing#licenseAssignment",
    "etags": "etag value",
    "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-50GB/user/alex@example.com",
    "userId": "alex@example.com",
    "productId": "Google-Drive-storage",
    "skuId": "Google-Drive-storage-50GB",
    "skuName": "Google Drive storage 50 GB",
    "productName": "Google Drive storage"
  },
  {
    "kind": "licensing#licenseAssignment",
    "etags": "etag value",
    "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-200GB/user/keshav@example.com",
    "userId": "keshav@example.com",
    "productId": "Google-Drive-storage",
    "skuId": "Google-Drive-storage-200GB",
    "skuName": "Google Drive storage 200 GB",
    "productName": "Google Drive storage"
  },
  ...
}

如需了解详情,请参阅 licensesAssignments listForProduct 方法参考页面。

检索为特定产品 SKU 分配了许可的所有用户

如需获取拥有特定产品 SKU 许可的所有用户的列表,请使用以下 GET HTTP 请求。添加 Authorization 标头,如向请求授权中所述。customerId 查询字符串是客户的主域名。maxResults 查询字符串决定了 API 响应中返回的用户条目数量:

GET https://www.googleapis.com/apps/licensing/v1/product/productId/sku/skuId/users?customerId=primary domain name&maxResults=max results per response page

如需了解产品和 SKU ID,请参阅 API 的可用产品和 SKU

下例返回 example.com 网域中被分配了 Google-云端硬盘存储空间-200GB SKU 许可的所有用户的第一页。响应每页会列出两个用户条目:

GET https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-200GB/users?customerId=example.com&maxResults=2

成功的响应会返回 200 HTTP 状态代码。如需了解可能的错误代码,请参阅 API 的错误代码。如果成功,响应会返回 JSON 格式的许可列表。

JSON 响应

{
  "kind" : "licensing#licenseAssignmentList",
   "etag": "etag value",
   "nextPageToken" : "next page token's value",
   "items": [
    {
     "kind": "licensing#licenseAssignment",
     "etags": "etag value",
     "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-200GB/user/alex@example.com",
     "userId": "alex@example.com",
     "productId": "Google-Drive-storage",
     "skuId": "Google-Drive-storage-200GB",
     "skuName": "Google Drive storage 200 GB",
     "productName": "Google Drive storage"
    },
    {
     "kind": "licensing#licenseAssignment",
     "etags": "etag value",
     "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-200GB/user/mary@example.com",
     "userId": "mary@example.com",
     "productId": "Google-Drive-storage",
     "skuId": "Google-Drive-storage-200GB",
     "skuName": "Google Drive storage 200 GB",
     "productName": "Google Drive storage"
    },
    ...
  }

如需了解详情,请参阅 licensesAssignments listForProductAndSku 方法参考页面。

按产品 SKU 检索特定用户的许可

如需按产品 SKU 获取特定用户的许可,请使用以下 GET HTTP 请求。添加 Authorization 标头,如向请求授权中所述。如需了解产品和 SKU ID,请参阅该 API 的可用产品和 SKU

GET https://www.googleapis.com/apps/licensing/v1/product/productId/sku/skuId/user/userId

以下示例为 userId 为 alex@example.com 的用户购买了 Google 云端硬盘存储空间 50GB 产品 SKU:

GET https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-50GB/user/alex@example.com

如果用户拥有此许可,是一个成功的响应和一个 200 HTTP 状态代码。如需了解可能的错误代码,请参阅 API 的错误代码。如果成功,响应将以 JSON 格式返回用户的许可。

JSON 响应

{
  "kind": "licensing#licenseAssignment",
  "etag": "etag value",
  "selfLink": "https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-50GB/user/alex@example.com",
  "userId": "keshav@example.com",
  "productId": "Google-Drive-storage",
  "skuId": "Google-Drive-storage-50GB",
  "skuName": "Google Drive storage 50 GB",
  "productName": "Google Drive storage"
}

如需了解详情,请参阅 licensesAssignments get 方法参考页面。

删除许可

如需取消分配用户的许可,请使用以下 DELETE HTTP 请求。添加 Authorization 标头,如向请求授权中所述。如需了解产品和 SKU ID,请参阅该 API 的可用产品和 SKU

DELETE https://www.googleapis.com/apps/licensing/v1/product/productId/sku/skuId/user/userId

在下例中,userId 为 alex@example.com 的用户未分配 50GB 的 Google 云端硬盘存储空间许可:

DELETE https://www.googleapis.com/apps/licensing/v1/product/Google-Drive-storage/sku/Google-Drive-storage-50GB/user/alex@example.com

成功的响应会返回 200 HTTP 状态代码。如需了解可能的错误代码,请参阅 API 的错误代码

如需了解详情,请参阅 licensesAssignments delete 方法参考页面。

错误代码

如果请求失败,响应中会简要说明错误:

错误代码 说明
400 请求错误 - 用户电子邮件地址无效。
400 请求有误 - SKU/产品不存在。
401 操作者没有调用此 API 的凭据。
404 如果用户没有此许可,响应将包含“未找到”错误代码。
412 尚未满足前提条件。如需详细了解此错误,请查看 message 字段。例如:
  • Auto License switching is not allowed.
  • Auto License un-assignment is not allowed.
  • For reassign operations, the new SKU should be different from the old SKU: sku
  • Reassign operation can't be performed on different products: product1, product2
  • Reassign operation can't be performed on different users: user1, user2
  • There aren't enough available licenses for the specified product-SKU pair
  • User already has a license for the specified product and SKU
  • User already has a license of the product, but with a different SKU. To reassign a new SKU for this product, use the 'update' operation.
503 License Manager 服务不可用。