Crea e gestisci stampanti

Le richieste di esempio in questa pagina mostrano come gestire le stampanti con l'API Chrome Printer Management.

Tutte le richieste di esempio utilizzano le seguenti variabili:

  • TOKEN: il token OAuth 2.0 della tua applicazione.
  • CUSTOMER_ID: l'ID cliente univoco dell'account aziendale, preceduto da "C". (Esempio: C123abc4) Puoi anche inserire my_customer per indicare l'ID cliente del tuo account.

Elenco dei modelli di stampante

Questo esempio richiede un elenco di tutti i modelli di stampanti supportati.

Richiesta

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

Risposta

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

Elencare o cercare stampanti

Questo esempio richiede un elenco di tutte le stampanti visibili nell'ID unità organizzativa 04fatzly26exj7b e che contengono la parola Lobby nel nome visualizzato o nella descrizione della stampante. Le stampanti aggiunte in un'unità organizzativa principale sono visibili alle unità organizzative secondarie, quindi la risposta potrebbe includere stampanti che non si trovano nell'unità organizzativa 04fatzly26exj7b.

Richiesta

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

Risposta

{
  "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
    }
  ]
}

Ottenere una stampante specifica

Questo esempio richiede i dettagli di una stampante con l'ID 0gjdgxs2zla0y7.

Richiesta

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

Risposta

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

Creare una stampante

Questo esempio aggiunge una nuova stampante nell'ID unità organizzativa 04fatzly26exj7b.

Richiesta

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"

Risposta

Una risposta corretta include l'ID della stampante appena creata:

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

Aggiornare una stampante

Questo esempio aggiorna la descrizione dell'ID stampante 0gjdgxs0o422uq.

Richiesta

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"

Risposta

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

Eliminare una stampante

Questo esempio elimina l'ID stampante 0gjdgxs0o422uq.

Richiesta

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

Risposta

Una risposta positiva è vuota. {}

Creare più stampanti in una sola richiesta

Questo esempio crea più stampanti in un'unica richiesta utilizzando il metodo batchCreatePrinters.

Richiesta

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"

Risposta

{
  "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
    }
  ]
}

Eliminare più stampanti in un'unica richiesta

Questo esempio elimina più stampanti in una singola richiesta utilizzando il metodo batchDeletePrinters.

Richiesta

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"

Risposta

Una risposta corretta include gli ID dei server di stampa eliminati:

{
  "printerIds": [
    "0gjdgxs2d6170e",
    "0gjdgxs0sbbh87"
  ]
}