Connectors API 程式碼範例

如要瞭解 API 功能,請參閱 Connectors API

這個頁面上的所有要求都會使用下列變數:

  • $TOKEN - OAuth 2.0 權杖
  • $CUSTOMER - 客戶 ID 或字面值 my_customer
  • $PAGE_TOKEN - 從前一頁回應取得的頁面符記
  • $CONNECTOR_CONFIG_ID - 連接器設定的 ID。產生的 ID 格式為大寫 UUID (例如 550E8400-E29B-41D4-A716-446655440000)。

列出連接器設定

如要列出客戶網域的連接器設定,請使用 list 方法。分頁瀏覽結果時,您可以選擇提供 page_size (或 pageSize) 和 page_token (或 pageToken) 查詢參數:

  • page_size / pageSize:要傳回的連接器設定數量上限。如未指定,預設頁面大小為 50,上限為 100。
  • page_token / pageToken:先前 list 呼叫傳回的頁面權杖。

要求

curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/connectorConfigs?page_size=50&page_token=$PAGE_TOKEN"

回應

{
  "connectorConfigs": [
    {
      "name": "customers/my_customer/connectorConfigs/550E8400-E29B-41D4-A716-446655440000",
      "displayName": "Configuration 1",
      "type": "REPORTING",
      "details": {
        "googleSecOpsConfig": {
          "host": "example.googlesecops.com",
          "reportingSettings": {
            "enabledDefaultEvents": [
              "ALL_DEFAULT_EVENTS"
            ],
            "enabledOptInEvents": [
              "PASSWORD_BREACH_EVENT",
              "URL_NAVIGATION_EVENT"
            ],
            "enabledDeviceEvents": [
              "ALL_DEVICE_EVENTS"
            ]
          }
        }
      },
      "status": {
        "state": "ENABLED"
      }
    }
  ],
  "nextPageToken": "<next_page_token>"
}

取得連接器設定

如要根據 ID 擷取特定連接器設定,請使用 get 方法。

要求

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

回應

{
  "name": "customers/my_customer/connectorConfigs/550E8400-E29B-41D4-A716-446655440000",
  "displayName": "Configuration 1",
  "type": "REPORTING",
  "details": {
    "googleSecOpsConfig": {
      "host": "example.googlesecops.com",
      "reportingSettings": {
        "enabledDefaultEvents": [
          "ALL_DEFAULT_EVENTS"
        ],
        "enabledOptInEvents": [
          "PASSWORD_BREACH_EVENT",
          "URL_NAVIGATION_EVENT"
        ],
        "enabledDeviceEvents": [
          "ALL_DEVICE_EVENTS"
        ]
      }
    }
  },
  "status": {
    "state": "ENABLED"
  }
}

建立連接器設定

如要為客戶網域建立新的連接器設定,請使用 create 方法。您可以選擇設定 connector_config_id (或 connectorConfigId) 查詢參數,提供自訂 ID。如未提供 ID,伺服器會產生大寫的 UUID。

要求

curl -X POST \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "displayName": "Configuration 1",
    "type": "REPORTING",
    "details": {
      "googleSecOpsConfig": {
        "apiKey": "api-key",
        "host": "example.googlesecops.com",
        "reportingSettings": {
          "enabledDefaultEvents": [
            "ALL_DEFAULT_EVENTS"
          ],
          "enabledOptInEvents": [
            "PASSWORD_BREACH_EVENT"
          ],
          "enabledDeviceEvents": [
            "ALL_DEVICE_EVENTS"
          ]
        }
      }
    }
  }' \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/connectorConfigs?connector_config_id=$CONNECTOR_CONFIG_ID"

回應

{
  "name": "customers/my_customer/connectorConfigs/550E8400-E29B-41D4-A716-446655440000",
  "displayName": "Configuration 1",
  "type": "REPORTING",
  "details": {
    "googleSecOpsConfig": {
      "host": "example.googlesecops.com",
      "reportingSettings": {
        "enabledDefaultEvents": [
          "ALL_DEFAULT_EVENTS"
        ],
        "enabledOptInEvents": [
          "PASSWORD_BREACH_EVENT"
        ],
        "enabledDeviceEvents": [
          "ALL_DEVICE_EVENTS"
        ]
      }
    }
  },
  "status": {
    "state": "ENABLED"
  }
}

更新連接器設定

您可以透過下列任一方式更新連接器設定:

  • 沒有更新遮罩:如果未提供 updateMask 查詢參數,系統會更新要求中設定的所有欄位。
  • 使用更新遮罩:如果指定 updateMask 查詢參數,系統只會更新遮罩中列出的欄位。
  • 使用對應於 * 的更新遮罩:如果 updateMask 設為 *,更新會視為完整取代 (等同於建立)。

範例 1:僅更新遮罩指定目標 displayName

在這個選項中,提供 updateMask=displayName 可確保只更新 displayName,即使主體中提供其他欄位也一樣。

要求

curl -X PATCH \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "displayName": "Updated name"
  }' \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/connectorConfigs/$CONNECTOR_CONFIG_ID?updateMask=displayName"

回應

{
  "name": "customers/my_customer/connectorConfigs/550E8400-E29B-41D4-A716-446655440000",
  "displayName": "Updated name",
  "type": "REPORTING",
  "details": {
    "googleSecOpsConfig": {
      "host": "example.googlesecops.com",
      "reportingSettings": {
        "enabledDefaultEvents": [
          "BROWSER_EXTENSION_INSTALL_EVENT"
        ],
        "enabledOptInEvents": [
          "PASSWORD_BREACH_EVENT"
        ],
        "enabledDeviceEvents": [
          "LOGIN_LOGOUT_EVENT"
        ]
      }
    }
  },
  "status": {
    "state": "ENABLED"
  }
}

範例 2:沒有更新遮罩 (更新要求中的所有欄位)

如果要求查詢字串中省略 updateMask,系統會更新 JSON 酬載中提供的所有欄位。

要求

curl -X PATCH \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "displayName": "Updated again",
    "details": {
      "googleSecOpsConfig": {
        "reportingSettings": {
          "enabledDefaultEvents": [
            "BROWSER_EXTENSION_INSTALL_EVENT",
            "CONTENT_TRANSFER_EVENT",
            "CONTENT_UNSCANNED_EVENT",
            "DATA_ACCESS_CONTROL_EVENT",
            "MALWARE_TRANSFER_EVENT"
          ]
        }
      }
    }
  }' \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/connectorConfigs/$CONNECTOR_CONFIG_ID"

回應

{
  "name": "customers/my_customer/connectorConfigs/550E8400-E29B-41D4-A716-446655440000",
  "displayName": "Updated again",
  "type": "REPORTING",
  "details": {
    "googleSecOpsConfig": {
      "host": "example.googlesecops.com",
      "reportingSettings": {
        "enabledDefaultEvents": [
          "BROWSER_EXTENSION_INSTALL_EVENT",
          "CONTENT_TRANSFER_EVENT",
          "CONTENT_UNSCANNED_EVENT",
          "DATA_ACCESS_CONTROL_EVENT",
          "MALWARE_TRANSFER_EVENT"
        ],
        "enabledOptInEvents": [
          "PASSWORD_BREACH_EVENT"
        ],
        "enabledDeviceEvents": [
          "ALL_DEVICE_EVENTS"
        ]
      }
    }
  },
  "status": {
    "state": "ENABLED"
  }
}

範例 3:* 的更新遮罩 (完整取代)

設定 updateMask=* 會以要求主體中提供的酬載,完全取代現有設定。

要求

curl -X PATCH \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "displayName": "New Updated Display Name",
    "type": "REPORTING",
    "details": {
      "googleSecOpsConfig": {
        "apiKey": "api-key",
        "host": "example.googlesecops.com",
        "reportingSettings": {
          "enabledOptInEvents": [
            "PASSWORD_BREACH_EVENT"
          ]
        }
      }
    }
  }' \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/connectorConfigs/$CONNECTOR_CONFIG_ID?updateMask=*"

回應

{
  "name": "customers/my_customer/connectorConfigs/550E8400-E29B-41D4-A716-446655440000",
  "displayName": "New Updated Display Name",
  "type": "REPORTING",
  "details": {
    "googleSecOpsConfig": {
      "host": "example.googlesecops.com",
      "reportingSettings": {
        "enabledOptInEvents": [
          "PASSWORD_BREACH_EVENT"
        ]
      }
    }
  },
  "status": {
    "state": "ENABLED"
  }
}

刪除連接器設定

如要刪除連接器設定,請使用 delete 方法。

要求

curl -X DELETE \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/connectorConfigs/$CONNECTOR_CONFIG_ID"

回應

{}