Chrome 管理 Chrome 瀏覽器 API 的程式碼範例

如要瞭解 API 功能,請參閱「Chrome Management Chrome Browsers API」。

本頁顯示的所有要求都會使用下列變數:

  • $TOKEN - OAuth 2.0 權杖
  • $CUSTOMER - 客戶 ID 或字面值 my_customer

列出已註冊的 Chrome 瀏覽器

如要列出已註冊的 Chrome 瀏覽器,請使用 /chromeBrowsers 端點。您可以使用 pageSize (上限和預設值為 100) 和 pageToken 參數控制分頁。使用 orderBy 指定結果的排序方式。 指定 filter 可縮小結果範圍。您可以使用 fields 查詢參數指定讀取遮罩。

= 和 : 僅支援 machine_name、annotated_asset_id 和 browser_version 欄位的萬用字元 (*) 比對 (前置字元 prefix*、後置字元 *suffix、子字串 *substring* 或存在 *)。

全域文字搜尋 (未指定欄位名稱) 會搜尋所有已建立索引的文字欄位。如果多個字詞以 AND 或空白字元分隔 (例如 filter=machine AND 73 或 filter=machine 73),每個字詞都必須與瀏覽器裝置上至少一個已建立索引的文字欄位相符 (即使是不同欄位也沒關係)。在單一引號字串中加上多個字詞 (例如 filter="machine name"),即可在單一欄位中搜尋完全相符的連續詞組。

篩選查詢示例

# Filter by machine name prefix (using ':' or '=')
filter=machine_name:LIX*

# Filter by annotated asset ID suffix
filter=annotated_asset_id="*1001"

# Filter by browser version substring
filter=browser_version:"*6367*"

# Global search across all indexed text fields (matches browsers containing both "machine" and "73" across any fields)
filter=machine AND 73

# Global search with implicit AND (equivalent to `machine AND 73`)
filter=machine 73

# Filter by machine name prefix and registration time range
filter=machine_name:LIX* AND last_registration_time>=2024-01-01T00:00:00Z

# Filter by Organizational Unit path
filter=org_unit_path=/Marketing

要求

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/chromeBrowsers?pageSize=2&orderBy=lastActivityTime+desc&filter=os_platform=WINDOWS"

回應

{
  "chromeBrowsers": [
    {
      "name": "customers/<customerId>/chromeBrowsers/<browserPermanentId1>",
      "browserPermanentId": "<browserPermanentId1>",
      "machineName": "CLIENT2024-01",
      "osPlatformType": "WINDOWS",
      "osVersion": "10.0.19045",
      "browserVersion": "124.0.6367.60",
      "annotatedUser": "user1@example.com",
      "annotatedLocation": "US-NYC",
      "annotatedAssetId": "ASSET-1001",
      "annotatedNotes": "Engineering workstation",
      "lastActivityTime": "2024-04-23T22:05:44.214362Z",
      "lastPolicySyncTime": "2024-04-23T22:00:00.000Z",
      "lastStatusReportTime": "2024-04-23T22:05:44.214362Z",
      "enrollmentDate": "2024-01-15T10:30:00.000Z",
      "orgUnitPath": "/Engineering",
      "policyCount": 15,
      "extensionCount": 8
    },
    {
      "name": "customers/<customerId>/chromeBrowsers/<browserPermanentId2>",
      "browserPermanentId": "<browserPermanentId2>",
      "machineName": "CLIENT2024-02",
      "osPlatformType": "WINDOWS",
      "osVersion": "11.0.22631",
      "browserVersion": "124.0.6367.60",
      "annotatedUser": "user2@example.com",
      "annotatedLocation": "US-MTV",
      "lastActivityTime": "2024-04-23T21:45:10.102000Z",
      "lastPolicySyncTime": "2024-04-23T21:40:00.000Z",
      "lastStatusReportTime": "2024-04-23T21:45:10.102000Z",
      "enrollmentDate": "2024-02-10T14:15:00.000Z",
      "orgUnitPath": "/Engineering",
      "policyCount": 12,
      "extensionCount": 5
    }
  ],
  "nextPageToken": "<nextPageToken>"
}

擷取受管理的 Chrome 瀏覽器

如要擷取單一已註冊的 Chrome 瀏覽器,請使用 /chromeBrowsers/{browser_permanent_id} 端點。您可以使用 fields 參數指定讀取遮罩。

要求

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/chromeBrowsers/<browserPermanentId1>"

回應

{
  "name": "customers/<customerId>/chromeBrowsers/<browserPermanentId1>",
  "browserPermanentId": "<browserPermanentId1>",
  "machineName": "CLIENT2024-01",
  "osPlatformType": "WINDOWS",
  "osVersion": "10.0.19045",
  "browserVersion": "124.0.6367.60",
  "annotatedUser": "user1@example.com",
  "annotatedLocation": "US-NYC",
  "annotatedAssetId": "ASSET-1001",
  "annotatedNotes": "Engineering workstation",
  "lastActivityTime": "2024-04-23T22:05:44.214362Z",
  "lastPolicySyncTime": "2024-04-23T22:00:00.000Z",
  "lastStatusReportTime": "2024-04-23T22:05:44.214362Z",
  "enrollmentDate": "2024-01-15T10:30:00.000Z",
  "orgUnitPath": "/Engineering",
  "policyCount": 15,
  "extensionCount": 8
}

更新 Chrome 瀏覽器的註解資訊

如要更新已註冊 Chrome 瀏覽器的加註欄位,請使用 /chromeBrowsers/{browser_permanent_id} 端點和 HTTP PATCH 方法,並提供 updateMask 查詢參數,指定要更新的欄位。

要求

  curl -X PATCH \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/chromeBrowsers/<browserPermanentId1>?updateMask=annotatedUser,annotatedNotes" \
  -d '{
    "annotatedUser": "newuser@example.com",
    "annotatedNotes": "Updated primary workstation"
  }'

回應

{
  "name": "customers/<customerId>/chromeBrowsers/<browserPermanentId1>",
  "browserPermanentId": "<browserPermanentId1>",
  "machineName": "CLIENT2024-01",
  "osPlatformType": "WINDOWS",
  "osVersion": "10.0.19045",
  "browserVersion": "124.0.6367.60",
  "annotatedUser": "newuser@example.com",
  "annotatedLocation": "US-NYC",
  "annotatedAssetId": "ASSET-1001",
  "annotatedNotes": "Updated primary workstation",
  "lastActivityTime": "2024-04-23T22:05:44.214362Z",
  "orgUnitPath": "/Engineering"
}

將 Chrome 瀏覽器移至新的機構單位

如要將受管理 Chrome 瀏覽器從一個機構單位移至另一個機構單位,請使用 /chromeBrowsers:move 端點。每次提出要求最多只能移動 600 個瀏覽器裝置。如果移動任何瀏覽器時發生錯誤,系統就不會移動任何指定的瀏覽器。

要求

  curl -X POST \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/chromeBrowsers:move" \
  -d '{
    "destinationOrgUnitId": "03ph8a2z3v",
    "resourceIds": [
      "customers/$CUSTOMER/chromeBrowsers/<browserPermanentId1>",
      "customers/$CUSTOMER/chromeBrowsers/<browserPermanentId2>"
    ]
  }'

回應

{}

刪除 Chrome 瀏覽器收集的資料

如要刪除受管理 Chrome 瀏覽器收集的資料,請使用 /chromeBrowsers/{browser_permanent_id} 端點和 HTTP DELETE。

要求

  curl -X DELETE \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/chromeBrowsers/<browserPermanentId1>"

回應

{}