Chrome Management Security Insights API 的程式碼範例

如要瞭解 API 功能,請參閱 Chrome 管理安全性深入分析 API

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

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

查看網域深入分析資訊的啟用狀態

如要查看網域洞察資料的啟用狀態,請使用 checkEnablementStatus 方法。

要求

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enterprise/securityInsights:checkEnablementStatus"

回應

{
  "insightsState": "INSIGHTS_ENABLED"
}

為網域啟用洞察資料

如要為網域啟用洞察資料,請使用 enable 方法。如有需要,您可以提供 targetOus,為特定機構單位設定 Chrome 連接器。如未設定 targetOus,則會在根機構單位設定 Chrome 連接器。

要求

  curl -X POST \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "targetOus": [
      "/corp/sales",
      "/eng"
    ]
  }' \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enterprise/securityInsights:enable"

回應

{
  "insightsState": "INSIGHTS_ENABLED"
}

停用網域的深入分析資訊

如要停用網域的洞察資料,請使用 disable 方法。

要求

  curl -X POST \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}' \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enterprise/securityInsights:disable"

回應

{
  "insightsState": "INSIGHTS_DISABLED"
}

查詢網域的概略內容傳輸摘要

如要擷取內容轉移的摘要,請使用 queryContentTransfers 方法。

要求

  curl -G \
  -H "Authorization: Bearer $TOKEN" \
  --data-urlencode "filter=event_time >= \"2026-05-01T00:00:00Z\" AND event_time <= \"2026-05-02T00:00:00Z\"" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enterprise/securityInsights:queryContentTransfers"

回應

{
  "summaries": [
    {
      "metric": "CONTENT_TRANSFERS_METRIC_TOTAL_SENSITIVE_TRANSFERS",
      "count": "918"
    },
    {
      "metric": "CONTENT_TRANSFERS_METRIC_TOTAL_DOWNLOADS",
      "count": "1537"
    },
    {
      "metric": "CONTENT_TRANSFERS_METRIC_TOTAL_UPLOADS",
      "count": "1532"
    },
    {
      "metric": "CONTENT_TRANSFERS_METRIC_SENSITIVE_UPLOADS",
      "count": "306"
    },
    {
      "metric": "CONTENT_TRANSFERS_METRIC_TOTAL_TRANSFERS",
      "count": "4596"
    },
    {
      "metric": "CONTENT_TRANSFERS_METRIC_SENSITIVE_PRINTS",
      "count": "305"
    },
    {
      "metric": "CONTENT_TRANSFERS_METRIC_SENSITIVE_DOWNLOADS",
      "count": "307"
    },
    {
      "metric": "CONTENT_TRANSFERS_METRIC_TOTAL_PRINTS",
      "count": "1527"
    }
  ]
}

查詢內容傳輸摘要和細目

如要查詢內容轉移作業,並依維度 (例如依 USER) 細分,請使用 queryContentTransfersBreakdowns 方法。

要求

  curl -G \
  -H "Authorization: Bearer $TOKEN" \
  --data-urlencode "breakdown=USER" \
  --data-urlencode "metric=CONTENT_TRANSFERS_METRIC_TOTAL_TRANSFERS" \
  --data-urlencode "fixedTimeRange=FIXED_TIME_RANGE_FOUR_WEEKS" \
  --data-urlencode "filter=user = \"user1\" AND event_time <= \"2026-05-01T00:00:00Z\"" \
  --data-urlencode "pageSize=5" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enterprise/securityInsights:queryContentTransfersBreakdowns"

回應

{
  "contentTransfersBreakdowns": [
    {
      "user": "user1",
      "summary": {
        "metric": "CONTENT_TRANSFERS_METRIC_TOTAL_TRANSFERS",
        "count": "20"
      }
    }
  ]
}

查詢網域的高層級網址造訪摘要

如要擷取可疑網址造訪記錄的高層級摘要,請使用 queryUrlVisits 方法。

要求

  curl -G \
  -H "Authorization: Bearer $TOKEN" \
  --data-urlencode "filter=event_time >= \"2026-05-01T00:00:00Z\" AND event_time <= \"2026-05-02T00:00:00Z\"" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enterprise/securityInsights:queryUrlVisits"

回應

{
  "summaries": [
    {
      "metric": "URL_VISITS_METRIC_HIGH_RISK_URL_VISITS",
      "count": "286"
    },
    {
      "metric": "URL_VISITS_METRIC_LOW_RISK_URL_VISITS",
      "count": "287"
    },
    {
      "metric": "URL_VISITS_METRIC_TOTAL_SUSPICIOUS_URL_VISITS",
      "count": "859"
    },
    {
      "metric": "URL_VISITS_METRIC_MEDIUM_RISK_URL_VISITS",
      "count": "286"
    }
  ]
}

查詢網址造訪摘要 (含明細)

如要查詢網址造訪次數,並依維度細分 (例如依 EVENT_DOMAIN 細分),請使用 queryUrlVisitsBreakdowns 方法。

要求

  curl -G \
  -H "Authorization: Bearer $TOKEN" \
  --data-urlencode "breakdown=EVENT_DOMAIN" \
  --data-urlencode "metric=URL_VISITS_METRIC_TOTAL_SUSPICIOUS_URL_VISITS" \
  --data-urlencode "fixedTimeRange=FIXED_TIME_RANGE_ONE_WEEK" \
  --data-urlencode "filter=event_domain = \"suspicious-domain.com\" AND event_time <= \"2026-05-01T00:00:00Z\"" \
  --data-urlencode "pageSize=5" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enterprise/securityInsights:queryUrlVisitsBreakdowns"

回應

{
  "urlVisitsBreakdowns": [
    {
      "eventDomain": "suspicious-domain.com",
      "summary": {
        "metric": "URL_VISITS_METRIC_TOTAL_SUSPICIOUS_URL_VISITS",
        "count": "132"
      }
    }
  ]
}