google-admin-sdk

How can I get available license via Google Workspace Admin SDK?


On Google Admin screen, I can get numbers of available licenses and used licenses shown below:

Google Admin Subscription

How can I get these numbers via API?

Note: I read this question and tried, but not worked well.

-- EDIT: 2021/07/15 --

My request:

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

Response from API:

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

Expectation: I want to get the data same as 2 available, 1132 assigned as the GUI shows.

To be honestly, I'm not satisfying even if I can get info via this API, because it seems not responding real-time data like GUI.


Solution

  • I think there are 2 ways this information can be obtain, but I can confirm for only one of them.

    1. Using the Report API that you mentioned.

    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
        }
    ]
    

    Important : The repot will always date 2 day back, so you can get the total number of licenses gsuite_enterprise_total_licenses in my example, and then use the Enterprise License Manager API to retrieve all currently assigned licenses

    2. Using the Reseller API

    GET https://reseller.googleapis.com/apps/reseller/v1/customers/{customerId}/subscriptions/{subscriptionId}
    
    {
      "numberOfSeats": integer,
      "maximumNumberOfSeats": integer,
      "licensedNumberOfSeats": integer,
      "kind": string
    }