יצירה וניהול של מדפסות

הבקשות לדוגמה בדף הזה ממחישות איך לנהל מדפסות באמצעות ממשק ה-API לניהול המדפסת ב-Chrome.

כל הבקשות לדוגמה משתמשות במשתנים הבאים:

  • $TOKEN: אסימון OAuth 2.0 של האפליקציה.
  • $CUSTOMER: מספר הלקוח הייחודי של החשבון הארגוני, ואחריו האות C. (לדוגמה: C123abc4) תוכלו גם להזין my_customer כדי לציין את מספר הלקוח של החשבון שלכם.

הצגת רשימה של דגמי מדפסות

הדוגמה הזו מבקשת רשימה של כל דגמי המדפסות הנתמכים.

בקשה

  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=="
}

הצגת רשימה או חיפוש של מדפסות

בדוגמה הזו מופיעה בקשה לקבל רשימה של כל המדפסות שמופיעות במזהה היחידה הארגונית 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
    }
  ]
}

החלפה של מדפסת ספציפית

הדוגמה הזו מבקשת פרטים עבור מדפסת עם המזהה 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"
}

יצירת מדפסת

בדוגמה הזו תתווסף מדפסת חדשה במזהה היחידה הארגונית 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"
}

עדכון מדפסת

הדוגמה הזו מעדכנת את התיאור של מזהה המדפסת 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"
}

מחיקת מדפסת

בדוגמה הזו מוחקים את מזהה המדפסת של המדפסת 0gjdgxs0o422uq.

בקשה

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

תשובה

אין תשובה תקינה. {}

יצירה של כמה מדפסות בבקשה אחת

הדוגמה הזו יוצרת כמה מדפסות בבקשה אחת באמצעות method 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"
  ]
}