ตัวอย่างโค้ดสำหรับ Connectors API

ดูข้อมูลเกี่ยวกับฟีเจอร์ API ได้ที่ Connectors API

คำขอทั้งหมดในหน้านี้ใช้ตัวแปรต่อไปนี้

  • $TOKEN - โทเค็น OAuth 2.0
  • $CUSTOMER - รหัสของลูกค้าหรือค่าตามตัวอักษร my_customer
  • $PAGE_TOKEN - โทเค็นหน้าเว็บที่ได้จากคำตอบของหน้าก่อนหน้า
  • $CONNECTOR_CONFIG_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>"
}

รับการกำหนดค่าเครื่องมือเชื่อมต่อ

หากต้องการเรียกข้อมูลการกำหนดค่าตัวเชื่อมต่อที่เฉพาะเจาะจงตามรหัส ให้ใช้เมธอด 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) หากไม่ได้ระบุรหัส เซิร์ฟเวอร์จะสร้าง 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"

การตอบกลับ

{}