Les exemples de requêtes sur cette page illustrent comment gérer les imprimantes avec l'API Chrome Printer Management.
Toutes les requêtes exemples utilisent les variables suivantes :
TOKEN: jeton OAuth 2.0 de votre application.CUSTOMER_ID: ID client unique du compte d'entreprise, précédé de la lettre "C". (Exemple :C123abc4) Vous pouvez également saisirmy_customerpour indiquer l'ID client de votre propre compte.
Lister les modèles d'imprimantes
Cet exemple demande la liste de tous les modèles d'imprimante compatibles.
Requête
curl -X GET \
--header "Authorization: Bearer TOKEN" \
"https://admin.googleapis.com/admin/directory/v1/customers/CUSTOMER_ID/chrome/printers:listPrinterModels"
Réponse
{
"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=="
}
Lister ou rechercher des imprimantes
Cet exemple demande une liste de toutes les imprimantes visibles dans l'ID d'unité organisationnelle 04fatzly26exj7b et contenant le mot Lobby dans le nom ou la description de l'imprimante. Les imprimantes ajoutées dans une unité organisationnelle parente sont visibles par les unités organisationnelles enfants. La réponse peut donc inclure des imprimantes qui ne se trouvent pas dans l'unité organisationnelle 04fatzly26exj7b.
Requête
curl -X GET \
--header "Authorization: Bearer TOKEN" \
"https://admin.googleapis.com/admin/directory/v1/customers/CUSTOMER_ID/chrome/printers?orgUnitId=04fatzly26exj7b&filter=Lobby"
Réponse
{
"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
}
]
}
Obtenir une imprimante spécifique
Cet exemple demande des informations sur une imprimante dont l'ID est 0gjdgxs2zla0y7.
Requête
curl -X GET \
--header "Authorization: Bearer TOKEN" \
"https://admin.googleapis.com/admin/directory/v1/customers/CUSTOMER_ID/chrome/printers/0gjdgxs2zla0y7"
Réponse
{
"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"
}
Créer une imprimante
Cet exemple ajoute une imprimante dans l'unité organisationnelle dont l'ID est 04fatzly26exj7b.
Requête
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"
Réponse
Une réponse positive inclut l'ID de l'imprimante nouvellement créée :
{
"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"
}
Mettre à jour une imprimante
Cet exemple met à jour la description de l'imprimante dont l'ID est 0gjdgxs0o422uq.
Requête
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"
Réponse
{
"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"
}
Supprimer une imprimante
Cet exemple supprime l'imprimante dont l'ID est 0gjdgxs0o422uq.
Requête
curl -X DELETE \
--header "Authorization: Bearer TOKEN" \
"https://admin.googleapis.com/admin/directory/v1/customers/CUSTOMER_ID/chrome/printers/0gjdgxs0o422uq"
Réponse
Une réponse réussie est vide. {}
Créer plusieurs imprimantes dans une même requête
Cet exemple crée plusieurs imprimantes dans une seule requête à l'aide de la méthode batchCreatePrinters.
Requête
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"
Réponse
{
"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
}
]
}
Supprimer plusieurs imprimantes en une seule requête
Cet exemple supprime plusieurs imprimantes en une seule requête à l'aide de la méthode batchDeletePrinters.
Requête
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"
Réponse
Une réponse positive inclut les ID des serveurs d'impression qui ont été supprimés :
{
"printerIds": [
"0gjdgxs2d6170e",
"0gjdgxs0sbbh87"
]
}