GAM icon indicating copy to clipboard operation
GAM copied to clipboard

New ChromeOS reports

Open jay0lee opened this issue 1 month ago • 7 comments

https://github.com/jay0lee/google-api-tracker/commit/b23aafef6396bca38e9a7fae3a19d4c83bdc8889

jay0lee avatar Nov 06 '25 23:11 jay0lee

Not quite ready for prime time. See: https://developers.google.com/chrome/management/reference/rest/v1/customers.reports/countActiveDevices The Query parameters date does not match the discovery document, or the APIs explorer Request parameters, The APIs explorer works. https://developers.google.com/chrome/management/reference/rest/v1/customers.reports/countActiveDevices?apix_params={"customer":"customers/C03pmm8ne","date.day":6,"date.month":11,"date.year":2025}

Unfortunately, the Python API call doesn't.

  startDate = todaysDate()
  kwargs = {'date.day': startDate.day, 'date.month': startDate.month, 'date.year': startDate.year}
  counts = callGAPI(cm.customers().reports(), 'countActiveDevices',
                    throwReasons=[GAPI.INVALID, GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED, GAPI.SERVICE_NOT_AVAILABLE],
                    retryReasons=GAPI.SERVICE_NOT_AVAILABLE_RETRY_REASONS,
                    customer=customerId, **kwargs)

$ gams config debug_level 1 print chromeactivedevices start today
connect: (chromemanagement.googleapis.com, 443)
send: GET /$discovery/rest?version=v1 HTTP/1.1
          Host: chromemanagement.googleapis.com
          content-length: 0
          user-agent: GAM 7.28.02 - https://github.com/GAM-team/GAM / GAM Team <[email protected]> / Python 3.14.0 final / macOS-26.1-arm64-arm-64bit-Mach-O arm64 /
          x-goog-api-client: cred-type/u
          authorization: Bearer *****
          accept-encoding: gzip, deflate


reply: 'HTTP/1.1 200 OK\r\n'
header: Content-Type: application/json; charset=UTF-8
header: Vary: Origin
header: Vary: X-Origin
header: Vary: Referer
header: Content-Encoding: gzip
header: Date: Fri, 07 Nov 2025 03:11:22 GMT
header: Server: ESF
header: X-XSS-Protection: 0
header: X-Frame-Options: SAMEORIGIN
header: X-Content-Type-Options: nosniff
header: Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
header: Transfer-Encoding: chunked

ERROR: Got an unexpected keyword argument date.day

taers232c avatar Nov 07 '25 03:11 taers232c

I figured it out by looking at the googleapiclient code. You need: kwargs = {'date_day': startDate.day, 'date_month': startDate.month, 'date_year': startDate.year} googleapiclient maps date_xxx to date.xxx

taers232c avatar Nov 07 '25 16:11 taers232c

gam print chromedevicecounts [todrive <ToDriveAttribute>*]                                                                                                                                                        
       [mode active|perboottype|perreleasechannel] [date <Date>]                                                                                                                                                   
       [formatjson [quotechar <Character>]]                                                                                                                                                                        
gam show chromedevicecounts                                                                                                                                                                                       
      [mode active|perboottype|perreleasechannel] [date <Date>]                                                                                                                                                   
      [formatjson]  

Does this look OK?

taers232c avatar Nov 07 '25 16:11 taers232c

Released in 7.28.02

taers232c avatar Nov 07 '25 23:11 taers232c

For future reference, Python's help function can be very helpful here:

help(cm.customers().reports().countActiveDevices)

outputs:


method(**kwargs) method of googleapiclient.discovery.Resource instance
    Get a count of active devices per set time frames.
    
    Args:
      customer: string, Required. Obfuscated customer ID prefixed with "customers/C" or "customers/my_customer". (required)
      date_day: integer, Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant.
      date_month: integer, Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day.
      date_year: integer, Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year.
      x__xgafv: string, V1 error format.
        Allowed values
          1 - v1 error format
          2 - v2 error format
    
    Returns:
      An object of the form:
    
        { # Response containing the number of active devices.
      "sevenDaysCount": "A String", # Number of active devices in the 7 days leading up to the date specified in the request.
      "thirtyDaysCount": "A String", # Number of active devices in the 30 days leading up to the date specified in the request.
    }

The googleapiclient library needs to convert .s in a argument to _ because . is meaningful, Python would look for an object named day with an attribute named day if it kept date.day. So the library replaces the . with _.

jay0lee avatar Nov 07 '25 23:11 jay0lee

Thanks

Ross Scroggs @.***

On Nov 7, 2025, at 3:53 PM, Jay Lee @.***> wrote:

jay0lee left a comment (GAM-team/GAM#1853) https://github.com/GAM-team/GAM/issues/1853#issuecomment-3505407343 For future reference, Python's help function can be very helpful here:

help(cm.customers().reports().countActiveDevices) outputs:

method(**kwargs) method of googleapiclient.discovery.Resource instance Get a count of active devices per set time frames.

Args:
  customer: string, Required. Obfuscated customer ID prefixed with "customers/C" or "customers/my_customer". (required)
  date_day: integer, Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant.
  date_month: integer, Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day.
  date_year: integer, Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year.
  x__xgafv: string, V1 error format.
    Allowed values
      1 - v1 error format
      2 - v2 error format

Returns:
  An object of the form:

    { # Response containing the number of active devices.
  "sevenDaysCount": "A String", # Number of active devices in the 7 days leading up to the date specified in the request.
  "thirtyDaysCount": "A String", # Number of active devices in the 30 days leading up to the date specified in the request.
}

The googleapiclient library needs to convert .s in a argument to _ because . is meaningful, Python would look for an object named day with an attribute named day if it kept date.day. So the library replaces the . with _.

— Reply to this email directly, view it on GitHub https://github.com/GAM-team/GAM/issues/1853#issuecomment-3505407343, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCTYL46WU3SIE6HJDRMNP333UWGJAVCNFSM6AAAAACLMKHVLSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKMBVGQYDOMZUGM. You are receiving this because you commented.

taers232c avatar Nov 08 '25 01:11 taers232c

Improved in 7.28.03

taers232c avatar Nov 08 '25 03:11 taers232c