创建和管理打印机

本页面上的请求示例说明了如何使用 Chrome Printer Management API 管理打印机。

所有示例请求都使用以下变量:

  • $TOKEN:应用的 OAuth 2.0 令牌。
  • $CUSTOMER:企业帐号的唯一客户 ID,以“C”开头。(示例:C123abc4)您还可以输入 my_customer 以表示您自己帐号的客户 ID。

列出打印机型号

此示例请求了所有受支持的打印机型号的列表。

请求

  curl -X GET \
  --header "Authorization: Bearer $TOKEN" \
  "https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printers:listPrinterModels"

响应

{
  "printerModels": [
    {
      "manufacturer": "Anitech",
      "displayName": "Anitech M24",
      "makeAndModel": "anitech m24"
    },
    {
      "manufacturer": "Apollo",
      "displayName": "Apollo P-2100",
      "makeAndModel": "apollo apollo 2100"
    },
    //...
    {
      "manufacturer": "Brother",
      "displayName": "Brother DCP-7025",
      "makeAndModel": "brother dcp-7025"
    },
    //...
  ],
  "nextPageToken": "CGQQAQ=="
}

列出或搜索打印机

此示例请求获取在组织单元 ID 04fatzly26exj7b 中显示且打印机显示名称或说明中包含 Lobby 一词的所有打印机的列表。

请求

  curl -X GET  \
  --header "Authorization: Bearer $TOKEN" \
  "https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printers?orgUnitId=04fatzly26exj7b&filter=Lobby"

响应

{
  "printers": [
     {
      "name": "customers/C0202nabg/chrome/printers/0gjdgxs2zla0y7",
      "id": "0gjdgxs2zla0y7",
      "displayName": "Jupiter",
      "description": "Guest printer in lobby Building C.",
      "makeAndModel": "xerox able 1406",
      "uri": "ipp://192.168.10.13",
      "createTime": "2021-03-11T21:41:34.779587Z",
      "orgUnitId": "04fatzly26exj7b" // Note: This printer was created in the same OU that we are searching within.
    },
    {
      "name": "customers/C0202nabg/chrome/printers/0gjdgxs1eqkb60",
      "id": "0gjdgxs1eqkb60",
      "displayName": "Mars",
      "description": "Printer in Lobby Building A",
      "uri": "ipp://192.168.10.11",
      "createTime": "2021-03-11T22:02:06.048469Z",
      "orgUnitId": "04fatzly4jbjho9", // Note: This printer was added in parent OU, yet is visible from the OU we are searching within.
      "useDriverlessConfig": true
    }
  ]
}

获取特定打印机

此示例请求获取 ID 为 0gjdgxs2zla0y7 的打印机的详细信息。

请求

  curl -X GET  \
  --header "Authorization: Bearer $TOKEN" \
  "https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printers/0gjdgxs2zla0y7"

响应

{
  "name": "customers/C0202nabg/chrome/printers/0gjdgxs2zla0y7",
  "id": "0gjdgxs2zla0y7",
  "displayName": "Jupiter",
  "description": "Guest printer in lobby Building C.",
  "makeAndModel": "xerox able 1406",
  "uri": "ipp://192.168.10.13",
  "createTime": "2021-03-11T21:41:34.779587Z",
  "orgUnitId": "04fatzly26exj7b"
}

创建打印机

此示例会在组织部门 ID 04fatzly26exj7b 中添加新打印机。

请求

curl -X POST \
  -H "Content-Type: application/json" \
  --header "Authorization: Bearer $TOKEN" \
  -d '{
    "displayName": "Mercury",
    "description": "Printer in the kitchen",
    "makeAndModel": "xerox able 1406",
    "uri": "ipp://192.168.10.14",
    "orgUnitId": "04fatzly26exj7b"
  }' \
  "https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printers"

响应

{
  "name": "customers/C0202nabg/chrome/printers/0gjdgxs0o422uq",
  "id": "0gjdgxs0o422uq", // Note: This is the ID of the newly created printer.
  "displayName": "Mercury",
  "description": "Printer in the kitchen",
  "makeAndModel": "xerox able 1406",
  "uri": "ipp://192.168.10.14",
  "createTime": "2021-03-11T23:19:27.180846Z",
  "orgUnitId": "04fatzly26exj7b"
}

更新打印机

此示例会更新打印机 ID 0gjdgxs0o422uq 的说明。

请求

curl -X PATCH \
  -H "Content-Type: application/json" \
  --header "Authorization: Bearer $TOKEN" \
  -d '{
    "description": "Printer in the office",
  }' \
  "https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printers/0gjdgxs0o422uq?updateMask=description"

响应

{
  "name": "customers/C0202nabg/chrome/printers/0gjdgxs0o422uq",
  "id": "0gjdgxs0o422uq",
  "displayName": "Mercury",
  "description": "Printer in the office",
  "makeAndModel": "xerox able 1406",
  "uri": "ipp://192.168.10.14",
  "createTime": "2021-03-11T23:19:27.180846Z",
  "orgUnitId": "04fatzly26exj7b"
}

删除打印机

此示例会删除打印机 ID 0gjdgxs0o422uq

请求

curl -X DELETE \
  --header "Authorization: Bearer $TOKEN" \
  "https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printers/0gjdgxs0o422uq"

响应

成功响应为空。{}

一次请求创建多个打印机

此示例使用 batchCreatePrinters 方法在单个请求中创建多个打印机。

请求

curl -X POST \
  -H "Content-Type: application/json" \
  --header "Authorization: Bearer $TOKEN" \
  -d '{
    "requests": [
      {
        "parent": "customers/$CUSTOMER",
        "printer": {
          "displayName": "Earth",
          "description": "Color printer",
          "useDriverlessConfig": true,
          "uri": "ipp://192.168.10.15",
          "orgUnitId": "04fatzly26exj7b"
        }
    },
    {
        "parent": "customers/$CUSTOMER",
        "printer": {
          "displayName": "Saturn",
          "description": "Color printer",
          "useDriverlessConfig": true,
          "uri": "ipp://192.168.10.16",
          "orgUnitId": "04fatzly26exj7b"
        }
    }
  ]
  }' \
  "https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printers:batchCreatePrinters"

响应

{
  "printers": [
    {
      "name": "customers/C0202nabg/chrome/printers/0gjdgxs0sbbh87",
      "id": "0gjdgxs0sbbh87",
      "displayName": "Saturn",
      "description": "Color printer",
      "uri": "ipp://192.168.10.16",
      "createTime": "2021-03-12T01:10:32.957084Z",
      "orgUnitId": "04fatzly26exj7b",
      "useDriverlessConfig": true
    },
    {
      "name": "customers/C0202nabg/chrome/printers/0gjdgxs2d6170e",
      "id": "0gjdgxs2d6170e",
      "displayName": "Earth",
      "description": "Color printer",
      "uri": "ipp://192.168.10.15",
      "createTime": "2021-03-12T01:10:32.956735Z",
      "orgUnitId": "04fatzly26exj7b",
      "useDriverlessConfig": true
    }
  ]
}

一次请求删除多台打印机

此示例使用 batchDeletePrinters 方法在单个请求中删除多台打印机。

请求

curl -X POST \
  -H "Content-Type: application/json" \
  --header "Authorization: Bearer $TOKEN" \
  -d '{
    "printerIds": ["0gjdgxs0sbbh87", "0gjdgxs2d6170e"]
  }' \
  "https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printers:batchDeletePrinters"

响应

{
  "printerIds": [ // Successfully deleted printers.
    "0gjdgxs2d6170e",
    "0gjdgxs0sbbh87"
  ]
}