本頁面的範例要求說明如何使用 Chrome 印表機管理 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/printServers"
回應
{
"printServers": [
{
"name": "customers/C0202nabg/chrome/printServers/0gjdgxs2zla0y7",
"id": "0gjdgxs2zla0y7",
"displayName": "Marketing Print Server",
"description": "Queue for corp marketing oversize jobs",
"uri": "ipp://192.168.10.13",
"createTime": "2021-03-11T21:41:34.779587Z",
"orgUnitId": "04fatzly26exj7b"
},
{
"name": "customers/C0202nabg/chrome/printServers/0gjdgxs1eqkb32",
"id": "0gjdgxs1eqkb32",
"displayName": "Production",
"description": "Production print server for user manuals",
"uri": "ipp://192.168.10.11",
"createTime": "2021-03-11T22:02:06.048469Z",
"orgUnitId": "04fatzly4jbjho9",
}
]
}
取得特定列印伺服器
這個範例會要求 ID 為 0gjdgxs2zla0y7
的列印伺服器詳細資料。
要求
curl -X GET \
--header "Authorization: Bearer $TOKEN" \
"https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printServers/0gjdgxs2zla0y7"
回應
{
"name": "customers/C0234nab1/chrome/printServers/0gjdgxs2zla0y7",
"id": "0gjdgxs2zla0y7",
"displayName": "Marketing Print Server",
"description": "Queue for corp marketing oversize jobs",
"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": "hr-dept",
"description": "HR queue for sensitive documents",
"uri": "ipp://192.168.10.14",
"orgUnitId": "04fatzly26exj7b"
}' \
"https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printServers"
回應
{
"name": "customers/C0234nab1/chrome/printServers/0gjdgxs0o422uq",
"id": "0gjdgxs0o422uq", // Note: This is the ID of the newly created print server.
"displayName": "hr-dept",
"description": "HR queue for sensitive documents",
"uri": "ipp://192.168.10.14",
"orgUnitId": "04fatzly26exj7b",
"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": "General HR dept print server",
}' \
"https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printServers/0gjdgxs0o422uq?updateMask=description"
回應
{
"name": "customers/C0234nab1/chrome/printServers/0gjdgxs0o422uq",
"id": "0gjdgxs0o422uq",
"displayName": "hr-dept",
"description": "General HR dept print server",
"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/printServers/0gjdgxs0o422uq"
回應
成功的回應會是空白。
在單一要求中建立多個列印伺服器
這個範例會使用 batchCreatePrintServers
方法建立多個列印伺服器。
要求
curl -X POST \
-H "Content-Type: application/json" \
--header "Authorization: Bearer $TOKEN" \
-d '{
"requests": [
{
"parent": "customers/$CUSTOMER",
"printServer": {
"displayName": "General print server",
"description": "Org-wide print queue",
"uri": "ipp://192.168.10.15",
"orgUnitId": "04fatzly26exj7b"
}
},
{
"parent": "customers/$CUSTOMER",
"printServer": {
"displayName": "Eng print server",
"description": "Print server for Eng use only",
"uri": "ipp://192.168.10.16",
"orgUnitId": "04fatzly26exj7b"
}
}
]
}' \
"https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printServers:batchCreatePrintServers"
回應
{
"printServers": [
{
"name": "customers/C0234nab1/chrome/printServers/0gjdgxs0sbbh87",
"id": "0gjdgxs0sbbh87",
"displayName": "General print server",
"description": "Org-wide print queue",
"uri": "ipp://192.168.10.15",
"createTime": "2021-03-12T01:10:32.957084Z",
"orgUnitId": "04fatzly26exj7b"
},
{
"name": "customers/C0234nab1/chrome/printServers/0gjdgxs2d6170e",
"id": "0gjdgxs2d6170e",
"displayName": "Eng print server",
"description": "Print server for Eng use only",
"uri": "ipp://192.168.10.16",
"createTime": "2021-03-12T01:10:32.956735Z",
"orgUnitId": "04fatzly26exj7b"
}
]
}
在單一要求中刪除多部印表機伺服器
這個範例會使用 batchDeletePrintServers
方法,在單一要求中刪除多個列印伺服器。
要求
curl -X POST \
-H "Content-Type: application/json" \
--header "Authorization: Bearer $TOKEN" \
-d '{
"printServerIds": ["0gjdgxs0sbbh87", "0gjdgxs2d6170e"]
}' \
"https://admin.googleapis.com/admin/directory/v1/customers/$CUSTOMER/chrome/printServers:batchDeletePrintServers"
回應
{
"printServerIds": [ // Successfully deleted print servers.
"0gjdgxs2d6170e",
"0gjdgxs0sbbh87"
]
}