【问题标题】:How can I get available license via Google Workspace Admin SDK?如何通过 Google Workspace Admin SDK 获得可用许可?
【发布时间】:2021-07-12 02:44:01
【问题描述】:

在 Google Admin 屏幕上,我可以获得如下所示的可用许可证和已用许可证的数量:

如何通过 API 获取这些数字?

注意:我阅读了this question 并尝试过,但效果不佳。

-- 编辑:2021/07/15--

我的要求:

https://developers.google.com/admin-sdk/reports/reference/rest/v1/customerUsageReports/get

  • 日期:(几天前)
  • 参数:accounts:gsuite_unlimited_total_licenses(来自Account Parameters

来自 API 的响应:

{
  "kind": "admin#reports#usageReports",
  "etag": "\"occ7bTD-Q2yefKPIae3LMOtCT9xQVZYBzlAbHU5b86Q/gt9BLwRjoWowpJCRESV3vBMjYMc\""
}

期望:我想获得与 GUI 显示的 2 available, 1132 assigned 相同的数据。

老实说,即使我可以通过此 API 获取信息,我也不满意,因为它似乎无法像 GUI 那样响应实时数据。

【问题讨论】:

  • I read this question and tried, but not worked well. - 你尝试了什么,你的要求是什么,你的回应是什么?
  • @RafaGuillermo 我试过这个:developers.google.com/admin-sdk/reports/reference/rest/v1/… 并找到 gsuite_unlimited_total_licensesgsuite_unlimited_used_licenses,但响应中没有数据。
  • 你能显示你提出的实际请求吗?你得到的回应是什么?你在期待什么?
  • @RafaGuillermo 我编辑了一个问题。

标签: google-admin-sdk


【解决方案1】:

我认为可以通过两种方式获取此信息,但我只能确认其中一种。

1.使用您提到的Report API

  • 注意:报告不是实时数据,因此您必须在执行日期前至少 2 天运行 API 调用并设置“日期”参数
  • 鉴于此,您必须在 {date} 参数中使用正确的日期运行此 GET 方法
GET https://admin.googleapis.com/admin/reports/v1/usage/dates/{date}
[
    {
        "BoolValue":  null,
        "DatetimeValueRaw":  null,
        "DatetimeValue":  null,
        "IntValue":  12065,
        "MsgValue":  null,
        "Name":  "accounts:gsuite_enterprise_total_licenses",
        "StringValue":  null
    },
    {
        "BoolValue":  null,
        "DatetimeValueRaw":  null,
        "DatetimeValue":  null,
        "IntValue":  12030,
        "MsgValue":  null,
        "Name":  "accounts:gsuite_enterprise_used_licenses",
        "StringValue":  null
    }
]

重要:repot 将始终追溯到 2 天前,因此您可以在我的示例中获取许可证总数 gsuite_enterprise_total_licenses,然后使用 Enterprise License Manager API 检索所有当前分配的许可证

2.使用Reseller API

  • 从经销商的角度检索信息,您需要使用subscriptions.get 方法,提供您的customerIdsubscriptionId,调用以下GET 请求:
GET https://reseller.googleapis.com/apps/reseller/v1/customers/{customerId}/subscriptions/{subscriptionId}
  • 它的响应将是一个 subscriptions 资源,其中包含有关许可证和 Seats object 的各种信息,如果您将其展开如下所示:
{
  "numberOfSeats": integer,
  "maximumNumberOfSeats": integer,
  "licensedNumberOfSeats": integer,
  "kind": string
}

【讨论】:

    【解决方案2】:

    答案:

    您只能使用 API 获取分配的许可证数量,可用的数量不会公开,因此不会返回。

    更多信息:

    假设您已为您的域分配了许可证,并且查询 API 的用户有权访问此信息,您可以通过以下请求检索数据:

    curl \
      'https://admin.googleapis.com/admin/reports/v1/usage/dates/2021-07-10?parameters=accounts%3Agsuite_unlimited_total_licenses&fields=*&key=[YOUR_API_KEY]' \
      --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
      --header 'Accept: application/json' \
      --compressed
    

    虽然没有必要,但我添加了参数field=* 以确保返回所有数据。

    这给了我这样的回应:

    {
      "kind": "admin#reports#usageReports",
      "etag": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "usageReports": [
        {
          "kind": "admin#reports#usageReport",
          "date": "2021-07-10",
          "etag": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          "entity": {
            "type": "CUSTOMER",
            "customerId": "C0136mgul"
          },
          "parameters": [
            {
              "name": "accounts:gsuite_unlimited_total_licenses",
              "intValue": "233"
            }
          ]
        }
      ]
    }
    

    在这里,您可以看到 accounts:gsuite_unlimited_total_licensesintValue 是 233 - 这反映在 UI 中:

    功能要求:

    但是,您可以让 Google 知道这是一项对于访问他们的 API 很重要的功能,并且您想请求他们实施它。

    Google 的Issue Tracker 是开发人员报告问题并为其开发服务提出功能请求的地方,我强烈建议您在那里提出功能请求。提交此文件的最佳组件是Google Admin SDK component,带有Feature Request 模板。

    【讨论】:

      猜你喜欢
      • 2021-03-28
      • 1970-01-01
      • 2014-11-23
      • 1970-01-01
      • 2023-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-04
      相关资源
      最近更新 更多