คำขอตัวอย่างในหน้านี้แสดงให้เห็นวิธีจัดการเครื่องพิมพ์ด้วย Chrome Printer Management API
คำขอตัวอย่างทั้งหมดใช้ตัวแปรต่อไปนี้
TOKEN: โทเค็น OAuth 2.0 ของแอปพลิเคชันCUSTOMER_ID: รหัสลูกค้าที่ไม่ซ้ำกัน ของบัญชีองค์กร โดยมี "C" นำหน้า (ตัวอย่าง:C123abc4) คุณยังป้อนmy_customerเพื่อระบุรหัสลูกค้าของบัญชีของคุณเองได้ด้วย
แสดงรายการรุ่นเครื่องพิมพ์
ตัวอย่างนี้ขอรายการรุ่นเครื่องพิมพ์ที่รองรับทั้งหมด
ส่งคำขอ
curl -X GET \
--header "Authorization: Bearer TOKEN" \
"https://admin.googleapis.com/admin/directory/v1/customers/CUSTOMER_ID/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=="
}
แสดงรายการหรือค้นหาเครื่องพิมพ์
ตัวอย่างนี้ขอรายการเครื่องพิมพ์ทั้งหมดที่มองเห็นได้ในรหัสหน่วยขององค์กร 04fatzly26exj7b และมีคำว่า Lobby ในชื่อที่แสดงหรือคำอธิบายของเครื่องพิมพ์ หน่วยขององค์กรย่อยจะเห็นเครื่องพิมพ์ที่เพิ่มในหน่วยขององค์กรระดับบนสุด ดังนั้นคำตอบอาจรวมถึงเครื่องพิมพ์ที่ไม่ได้อยู่ในหน่วยขององค์กร 04fatzly26exj7b
ส่งคำขอ
curl -X GET \
--header "Authorization: Bearer TOKEN" \
"https://admin.googleapis.com/admin/directory/v1/customers/CUSTOMER_ID/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"
},
{
"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",
"useDriverlessConfig": true
}
]
}
รับเครื่องพิมพ์ที่เฉพาะเจาะจง
ตัวอย่างนี้ขอรายละเอียดสำหรับเครื่องพิมพ์ที่มีรหัส 0gjdgxs2zla0y7
ส่งคำขอ
curl -X GET \
--header "Authorization: Bearer TOKEN" \
"https://admin.googleapis.com/admin/directory/v1/customers/CUSTOMER_ID/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"
}
สร้างเครื่องพิมพ์
ตัวอย่างนี้จะเพิ่มเครื่องพิมพ์ใหม่ในรหัสหน่วยขององค์กร 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_ID/chrome/printers"
การตอบกลับ
การตอบกลับที่สำเร็จจะมีรหัสของเครื่องพิมพ์ที่สร้างขึ้นใหม่ดังนี้
{
"name": "customers/C0202nabg/chrome/printers/0gjdgxs0o422uq",
"id": "0gjdgxs0o422uq",
"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"
}
อัปเดตเครื่องพิมพ์
ตัวอย่างนี้จะอัปเดตคำอธิบายของรหัสเครื่องพิมพ์ 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_ID/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"
}
ลบเครื่องพิมพ์
ตัวอย่างนี้จะลบเครื่องพิมพ์ที่มีรหัสเครื่องพิมพ์ 0gjdgxs0o422uq
ส่งคำขอ
curl -X DELETE \
--header "Authorization: Bearer TOKEN" \
"https://admin.googleapis.com/admin/directory/v1/customers/CUSTOMER_ID/chrome/printers/0gjdgxs0o422uq"
การตอบกลับ
การตอบกลับที่สำเร็จจะไม่มีเนื้อหา {}
สร้างเครื่องพิมพ์หลายเครื่องในคำขอเดียว
ตัวอย่างนี้สร้างเครื่องพิมพ์หลายเครื่องในคำขอเดียวโดยใช้วิธี
batchCreatePrinters
ส่งคำขอ
curl -X POST \
-H "Content-Type: application/json" \
--header "Authorization: Bearer TOKEN" \
-d '{
"requests": [
{
"parent": "customers/CUSTOMER_ID",
"printer": {
"displayName": "Earth",
"description": "Color printer",
"useDriverlessConfig": true,
"uri": "ipp://192.168.10.15",
"orgUnitId": "04fatzly26exj7b"
}
},
{
"parent": "customers/CUSTOMER_ID",
"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_ID/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_ID/chrome/printers:batchDeletePrinters"
การตอบกลับ
การตอบกลับที่สำเร็จจะมีรหัสของเซิร์ฟเวอร์การพิมพ์ที่ถูกลบ
{
"printerIds": [
"0gjdgxs2d6170e",
"0gjdgxs0sbbh87"
]
}