דוגמאות קוד

הבקשות הבאות ממחישות איך מנהלים את המדיניות באמצעות ה-Policy API. לפני שמתחילים, חשוב לעיין בסקירה הכללית על Chrome Policy API כדי לקבל סיכום ברמה גבוהה של התכונות של ה-API הזה.

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

  • $TOKEN – אסימון OAuth 2
  • $CUSTOMER – מספר הלקוח או מספר הלקוח my_customer

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

כדי להציג סכימות שקשורות רק לכללי מדיניות למדפסות, נחיל את הפרמטר filter על בקשת הרשימה של שירות הסכימה. אפשר לשלוט בעימוד של התוצאה באמצעות הפרמטרים pageSize ו-pageToken.

בקשה

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policySchemas?filter=chrome.printers&pageSize=2"

תשובה

{
  "policySchemas": [
    {
      "name": "customers/C0202nabg/policySchemas/chrome.printers.AllowForUsers",
      "policyDescription": "Allows a printer for users in a given organization.",
      "additionalTargetKeyNames": [
        {
          "key": "printer_id",
          "keyDescription": "Id of printer as visible in Admin SDK printers API."
        }
      ],
      "definition": {
        "messageType": [
          {
            "name": "AllowForUsers",
            "field": [
              {
                "name": "allowForUsers",
                "number": 1,
                "label": "LABEL_OPTIONAL",
                "type": "TYPE_BOOL"
              }
            ]
          }
        ]
      },
      "fieldDescriptions": [
        {
          "field": "allowForUsers",
          "description": "Controls whether a printer is allowed for users in a given organization."
        }
      ],
      "schemaName": "chrome.printers.AllowForUsers"
    },
    {
      "name": "customers/C0202nabg/policySchemas/chrome.printers.AllowForDevices",
      "policyDescription": "Allows a printer for devices in a given organization.",
      "additionalTargetKeyNames": [
        {
          "key": "printer_id",
          "keyDescription": "Id of printer as visible in Admin SDK printers API."
        }
      ],
      "definition": {
        "messageType": [
          {
            "name": "AllowForDevices",
            "field": [
              {
                "name": "allowForDevices",
                "number": 1,
                "label": "LABEL_OPTIONAL",
                "type": "TYPE_BOOL"
              }
            ]
          }
        ]
      },
      "fieldDescriptions": [
        {
          "field": "allowForDevices",
          "description": "Controls whether a printer is allowed for devices in a given organization."
        }
      ],
      "schemaName": "chrome.printers.AllowForDevices"
    }
  ],
  "nextPageToken": "AEbDN_obE8A98T8YhIeU9VCIZhEBylLBwZRQpGu_DUug-mU4bnzcDx30UnO2xMuuImvfVpmeuXRF6VhJ4OmZpZ4H6EaRvu2qMOPxVN_u"
}

חיפוש סכימות

אפשר ליצור שאילתות חיפוש מורכבות באמצעות הפרמטר filter= בבקשה לרשימת שירותי Schema. לדוגמה, אם רוצים לחפש סכימות שבתיאור שלהן מופיעה המילה "מדפסת" ואת המילה "מכשירים", אפשר להחיל את הערך הבא על המסנן name=printers AND description=devices.

איך מציגים סכימות של מדיניות

בקשה

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policySchemas?filter=name=printers%20AND%20description=devices"

תשובה

{
  "policySchemas": [
    {
      "name": "customers/C0202nabg/policySchemas/chrome.printers.AllowForDevices",
      "policyDescription": "Allows a printer for devices in a given organization.",
      "additionalTargetKeyNames": [
        {
          "key": "printer_id",
          "keyDescription": "Id of printer as visible in Admin SDK printers API."
        }
      ],
      "definition": {
        "messageType": [
          {
            "name": "AllowForDevices",
            "field": [
              {
                "name": "allowForDevices",
                "number": 1,
                "label": "LABEL_OPTIONAL",
                "type": "TYPE_BOOL"
              }
            ]
          }
        ]
      },
      "fieldDescriptions": [
        {
          "field": "allowForDevices",
          "description": "Controls whether a printer is allowed for devices in a given organization."
        }
      ],
      "schemaName": "chrome.printers.AllowForDevices"
    }
  ]
}

קבלת סכימה מסוימת

בתוצאה שלמעלה מופיעה רשימה של סכימות מדיניות נתמכות. בכל סכימה יש שדה name שמזהה את הסכימה. בעתיד, אחרי שתדעו את שם הסכימה, תוכלו לקרוא את הסכימה המסוימת ישירות על ידי התייחסות לשם הסכימה שמופיע בכתובת ה-URL של הבקשה.

בואו נראה דוגמה לסכימה chrome.printers.AllowForUsers.

בקשה

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policySchemas/chrome.printers.AllowForUsers"

תשובה

{
  "name": "customers/C0202nabg/policySchemas/chrome.printers.AllowForUsers",
  "policyDescription": "Allows a printer for users in a given organization.",
  "additionalTargetKeyNames": [
    {
      "key": "printer_id",
      "keyDescription": "Id of printer as visible in Admin SDK printers API."
    }
  ],
  "definition": {
    "messageType": [
      {
        "name": "AllowForUsers",
        "field": [
          {
            "name": "allowForUsers",
            "number": 1,
            "label": "LABEL_OPTIONAL",
            "type": "TYPE_BOOL"
          }
        ]
      }
    ]
  },
  "fieldDescriptions": [
    {
      "field": "allowForUsers",
      "description": "Controls whether a printer is allowed for users in a given organization."
    }
  ],
  "schemaName": "chrome.printers.AllowForUsers"
}

התשובה לסכימת המדיניות שלמעלה מתארת את הסכימה של המדיניות chrome.printers.AllowForUsers. שדה הודעה additionalTargetKeyNames. בשדה הזה מוסבר שהמדיניות הזו מחייבת לספק מפתחות או ערכים נוספים במהלך הטיפול במדיניות הזו. באופן ספציפי, במסגרת המדיניות הזו אנחנו תמיד צריכים לספק את המזהה של המדפסת.

קריאת ערך מדיניות

עכשיו נקרא מדיניות chrome.printers.AllowForUsers לגבי מדפסת ספציפית. הודעה על שימוש בשדה additionalTargetKeys לציון מזהה מדפסת בבקשה.

אפשר לקרוא מדיניות מיחידה ארגונית או מקבוצה.

בתשובה מופיע השדה sourceKey, שמציין מאיזו יחידה ארגונית או מאיזו קבוצה מגיע ערך המדיניות. ביחידות הארגוניות קיימות האפשרויות הבאות:

  • אם היחידה הארגונית המקורית זהה ליחידה הארגונית שצוינה בבקשה, המשמעות היא שהמדיניות חלה באופן מקומי על היחידה הארגונית הזאת.
  • אם היחידה הארגונית המקורית שונה מהיחידה הארגונית שצוינה בבקשה, המשמעות היא שהמדיניות עוברת בירושה מהיחידה הארגונית המקורית.
  • אם לא קיים sourceKey, או אם התשובה ריקה, המשמעות היא שהמדיניות לא מוגדרת עבור הלקוח ויש לה ערך ברירת מחדל במערכת.

עבור קבוצות Google, מפתח source יהיה תמיד זהה לקבוצה שצוינה בבקשה.

הדוגמה הבאה מתייחסת ליחידה ארגונית. בקשת Group תהיה זהה, מלבד ה-targetResource, שלפני המזהה שלו יופיעו "groups/" במקום "orgunits/".

בקשה

  curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        policyTargetKey: {
          targetResource: "orgunits/04fatzly4jbjho9",
          additionalTargetKeys: {"printer_id":"0gjdgxs208tpef"}
        },
        policySchemaFilter: "chrome.printers.AllowForDevices"
    }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies:resolve"

תשובה

{
  "resolvedPolicies": [
    {
      "targetKey": {
        "targetResource": "orgunits/03ph8a2z1xdnme9"
        "additionalTargetKeys": {"printer_id":"0gjdgxs208tpef"}
      },
      "value": {
        "policySchema": "chrome.users.AllowForDevices",
        "value": {
          "allowForDevices": true
        }
      },
      "sourceKey": {
        "targetResource": "orgunits/03ph8a2z3qhz81k"
      }
    }
  ]
}

הערה: אפשר לאחזר את כל הישויות במשאבי היעד על ידי השמטת הערך additionalTargetKeys מהבקשה. לדוגמה, אם additionalTargetKeys יושמט מהבקשה שלמעלה, הוא יחזיר את כל המדפסות במשאב היעד שצוין.

קריאה של סעיפי מדיניות מרובים

הוספת מרחב שמות של סכימה עם כוכבית (למשל, chrome.printers.*) מאפשר לקרוא את הערכים של כל כללי המדיניות במרחב השמות הזה ביחידה ארגונית או בקבוצה ספציפית. מידע נוסף על סכימות המדיניות

הדוגמה הבאה מתייחסת ליחידה ארגונית. בקשת Group תהיה זהה, מלבד ה-targetResource, שלפני המזהה שלו יופיעו "groups/" במקום "orgunits/".

בקשה

  curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        policyTargetKey: {
          targetResource: "orgunits/04fatzly4jbjho9",
        },
        policySchemaFilter: "chrome.printers.*"
    }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies:resolve"

תשובה

{
  "resolvedPolicies": [
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "printer_id": "0gjdgxs0xd59y1"
        }
      },
      "value": {
        "policySchema": "chrome.printers.AllowForUsers",
        "value": {
          "allowForUsers": false
        }
      }
    },
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "printer_id": "0gjdgxs0xd59y1"
        }
      },
      "value": {
        "policySchema": "chrome.printers.AllowForDevices",
        "value": {
          "allowForDevices": false
        }
      }
    },
    //...
  ],
  "nextPageToken": "AEbDN_pFvDeGSbQDkvMxr4UA0Ew7UEUw8aJyw95VPs2en6YxMmFcWQ9OQQEIeSkjnWFCQNyz5GGoOKQGEd50e2z6WqvM2w7sQz6TMxVOBD_4NmEHRWtIJCYymeYXWHIrNH29Ezl1wkeyYBAOKnE="
}

שינוי הערך של המדיניות

כפי שניתן לראות בתגובה לסכימת המדיניות, במדיניות chrome.printers.AllowForUsers יש שדה אחד בשם allowForUsers. השדה הזה הוא מסוג בוליאני. ערך לדוגמה של המדיניות יכול להיות {allowForUsers: false} או {allowForUsers: true}. במקרה הספציפי הזה יש לנו רק שדה אחד, אבל כללי מדיניות אחרים עשויים להכיל כמה שדות.

בבקשות לשינוי, אנחנו צריכים לציין updateMask. אנונימיזציה של עדכונים מפרטת את כל השדות שאנחנו רוצים לשנות. אם המדיניות כבר הוחלה באופן מקומי ביחידה הארגונית, השדות שלא מופיעים ברשימה באמצעות מסיכת עדכון יישארו ללא שינוי. אם המדיניות לא הוחלה באופן מקומי ביחידה הארגונית, בכל השדות שלא מופיעים ברשימה באמצעות מסיכת עדכון במקרים הרלוונטיים, הערכים שלהם יועתקו מהיחידה הארגונית ברמה העליונה של ההורה, והמדיניות במלואה תיושם באופן מקומי.

הדוגמאות הבאות מתייחסות ליחידה ארגונית. בקשות לקבוצה זהות, פרט למשאב targetResource, שלפני המזהה שלהן יהיו "groups/" במקום "orgunits/". כאן לא נאפשר שימוש במדפסת 0gjdgxs208tpef למשתמשים במזהה היחידה הארגונית 04fatzly4jbjho9:

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        additionalTargetKeys: {"printer_id":"0gjdgxs208tpef"}
                        },
                policyValue: {
                        policySchema: "chrome.printers.AllowForUsers",
                        value: {allowForUsers: false}
                        },
                updateMask: {paths: "allowForUsers"}
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

תשובה

אין תשובה מוצלחת.

{}

שדות מרובי ערכים, כמו רשימות או מערכים, מסומנים בתווית "LABEL_REPEATED". כדי לאכלס שדות מרובי ערכים, צריך להשתמש בפורמט הבא של מערך JSON: [value1, value2, value3, ...].

לדוגמה, כדי להגדיר כתובות URL של מקורות עבור חבילות של אפליקציות ותוספים כ-test1.com , test2.com ו-test3.com, עלינו לשלוח את הבקשה הבאה:

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d "{
        requests: [
          {
            policy_target_key: {
              target_resource: 'orgunits/03ph8a2z28rz85a'
            },
            updateMask: {
              paths: ['extensionInstallSources']
            },
            policy_value: {
              policy_schema: 'chrome.users.appsconfig.AppExtensionInstallSources', 
              value: {
                extensionInstallSources: ['test1.com', 'test2.com', 'test3.com']
              }
            }
          }
        ]
      }" \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

תשובה

אין תשובה מוצלחת.

{}

יש שתי גרסאות לכל כללי המדיניות שכוללים שדות NullableDuration. הגרסה המקורית מקבלת מחרוזת רק כקלט עבור NullableDuration, ועכשיו היא הוצאה משימוש. יש להשתמש בגרסה של V2 שמחליפה את סוג משך הזמן בקלט מספרי. לדוגמה, כדי להגדיר את משך הסשן המקסימלי של משתמש ל-10 דקות, צריך לשלוח את הבקשה הבאה:

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d "{
        requests: [
          {
            policy_target_key: {
              target_resource: 'orgunits/03ph8a2z28rz85a'
            },
            updateMask: {
              paths: ['sessionDurationLimit']
            },
            policy_value: {
              policy_schema: 'chrome.users.SessionLengthV2',
              value: {
                sessionDurationLimit: {
                  duration: 10
                }
              }
            }
          }
        ]
      }" \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

תשובה

אין תשובה מוצלחת.

{}

שינוי של כמה כללי מדיניות בבת אחת

השיטה batchModify מאפשרת לשלוח כמה שינויים במדיניות בבת אחת. עם זאת, לא ניתן לקבץ יחד את כל כללי המדיניות. לפרטים נוספים, אפשר לעיין במדיניות בנושא עדכונים באצווה.

בדוגמה הזו נשנה, באותה בקשה, שתי כללי מדיניות שונים (chrome.printers.AllowForDevices ו-chrome.printers.AllowForUsers) לאותה מדפסת.

הדוגמה הבאה מתייחסת ליחידה ארגונית. בקשת Group תהיה זהה, מלבד ה-targetResource, שלפני המזהה שלו יופיעו "groups/" במקום "orgunits/".

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        additionalTargetKeys: {"printer_id":"0gjdgxs208tpef"}
                        },
                policyValue: {
                        policySchema: "chrome.printers.AllowForDevices",
                        value: {allowForDevices: true}
                        },
                updateMask: {paths: "allowForDevices"}
                },
                {
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        additionalTargetKeys: {"printer_id":"0gjdgxs208tpef"}
                        },
                policyValue: {
                        policySchema: "chrome.printers.AllowForUsers",
                        value: {allowForUsers: true}
                        },
                updateMask: {paths: "allowForUsers"}
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/C0202nabg/policies/orgunits:batchModify"

תשובה

אין תשובה מוצלחת.

{}

בירושה של ערך מדיניות ביחידה ארגונית

באמצעות השיטה batchInherit אפשר לשנות את סטטוס המדיניות ביחידה ארגונית מ'הוחלה באופן מקומי' ל'עברה בירושה'. הערכים המקומיים ינוקו, והמדיניות תירש את הערכים מיחידה ארגונית ברמה העליונה, במקרים הרלוונטיים.

בעזרת method batchInherit גם אפשר לשלוח כמה בקשות ירושה ממדיניות בו-זמנית. עם זאת, לא ניתן לקבץ יחד את כל כללי המדיניות. לפרטים נוספים, אפשר לעיין במדיניות בנושא עדכונים באצווה.

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly12wd3ox",
                        additionalTargetKeys: {"printer_id":"0gjdgxs208tpef"}
                        },
                policySchema: "chrome.printers.AllowForUsers"
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchInherit"

תשובה

אין תשובה מוצלחת.

{}

מחיקת ערך מדיניות בקבוצה

בעזרת method batchDelete אפשר למחוק מדיניות מקבוצה. הערכים המקומיים ינוקו.

בעזרת method batchDelete גם אפשר לשלוח כמה בקשות למחיקת מדיניות בבת אחת. עם זאת, לא ניתן לקבץ יחד את כל כללי המדיניות. לפרטים נוספים, אפשר לעיין במדיניות בנושא עדכונים באצווה.

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "groups/04fatzly12wd3ox",
                        additionalTargetKeys: {"printer_id":"0gjdgxs208tpef"}
                        },
                policySchema: "chrome.printers.AllowForUsers"
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/groups:batchDelete"

תשובה

אין תשובה מוצלחת.

{}

יש לפרט את סדר העדיפות של קבוצה

בעזרת השיטה listGroupPriorityOrdering אפשר להגדיר את סדר העדיפות של קבוצות Google באפליקציה.

הסדר של מזהי הקבוצות שמוחזרים מציין את העדיפות שבה יחולו ההגדרות שלהם על האפליקציה. כללי המדיניות של המזהים מאוחרים יותר יבוטלו על ידי כללי המדיניות שהמזהים שלהם מופיעים מוקדם יותר ברשימה.

חשוב לשים לב שהעדיפות הקבוצתית גבוהה יותר מהעדיפות של היחידה הארגונית.

בבקשה הזו, אנחנו מחזירים את סדר העדיפות של אפליקציית משתמש Chrome "exampleapp".

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        policyTargetKey: {
                additionalTargetKeys: {"app_id":"chrome:exampleapp"}
                },
        policyNamespace: 'chrome.users.apps'
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/groups:listGroupPriorityOrdering"

תשובה

{
  "policyTargetKey": {
    "additionalTargetKeys": {
      "app_id": "chrome:exampleapp"
    }
  },
  "policyNamespace": "chrome.users.apps",
  "groupIds": [
    "03ep43zb2k1nodu",
    "01t3h5sf2k52kol",
    "03q5sasy2ihwnlz"
  ]
}

עדכון של סדר העדיפויות של קבוצה

בעזרת method updateGroupPriorityOrdering אפשר לעדכן את סדר העדיפות של קבוצות Google באפליקציה מסוימת.

הסדר של מזהי הקבוצות בבקשה מציין את העדיפות שבה יחולו ההגדרות שלהם על האפליקציה. כללי המדיניות של המזהים מאוחרים יותר יבוטלו על ידי כללי המדיניות שהמזהים שלהם מופיעים מוקדם יותר ברשימה. הבקשה צריכה לכלול את כל מזהי הקבוצה שחלים כרגע על האפליקציה.

חשוב לשים לב שהעדיפות הקבוצתית גבוהה יותר מהעדיפות של היחידה הארגונית.

בבקשה הזו אנחנו מגדירים את סדר העדיפות של אפליקציית משתמש Chrome "exampleapp".

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        policyTargetKey: {
                additionalTargetKeys: {"app_id":"chrome:exampleapp"}
                },
        policyNamespace: 'chrome.users.apps',
        groupIds: ['03ep43zb2k1nodu', '01t3h5sf2k52kol', '03q5sasy2ihwnlz']
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/groups:updateGroupPriorityOrdering"

תשובה

אין תשובה מוצלחת.

{}

מדיניות טיפול הנדרשת באישור

סכימות מדיניות מסוימות מציינות 'הודעות' לערכים מסוימים של שדה מסוים שמחייבים אישור.

דוגמה למדיניות chrome.users.PluginVmAllowd:

{
  "name": "customers/C0202nabg/policySchemas/chrome.users.PluginVmAllowed",
  "policyDescription": "Parallels Desktop.",
  # ...
  "fieldDescriptions": [
    {
      "field": "pluginVmAllowed",
      "description": "N/A",
      "knownValueDescriptions": [
        {
          "value": "true",
          "description": "Allow users to use Parallels Desktop."
        },
        {
          "value": "false",
          "description": "Do not allow users to use Parallels Desktop."
        }
      ]
    },
    {
      "field": "ackNoticeForPluginVmAllowedSetToTrue",
      "description": "This field must be set to true to acknowledge the notice message associated with the field 'plugin_vm_allowed' set to value 'true'. Please see the notices listed with this policy for more information."
    }
  ],
  "notices": [
    {
      "field": "pluginVmAllowed",
      "noticeValue": "true",
      "noticeMessage": "By enabling Parallels Desktop, you agree to the Parallels End-User License Agreement specified at https://www.parallels.com/about/legal/eula/. Warning: Device identifiers may be shared with Parallels. Please see privacy policy for more details at https://www.parallels.com/about/legal/privacy/. The minimum recommended configuration includes an i5 processor, 16 GB RAM, and 128 GB storage: https://support.google.com/chrome/a/answer/10044480.",
      "acknowledgementRequired": true
    }
  ],
  "supportUri": "...",
  "schemaName": "chrome.users.PluginVmAllowed"
}

בדוגמה שלמעלה, הגדרת הערך true בשדה pluginVmAllowed משויכת להודעה עם acknowledgementRequired. כדי להגדיר כראוי את ערך השדה הזה ל-true, צריך לשלוח בקשה עם ציון של שדה האישור ackNoticeForPluginVmAllowedSetToTrue אל true. אחרת, תופיע שגיאה בבקשה.

בדוגמה הזו צריך לשלוח את הבקשה הבאה לשינוי באצווה.

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d "{
  'requests': [
    {
      'policyTargetKey': {
        'targetResource': 'orgunits/03ph8a2z10ybbh2'
      },
      'policyValue': {
        'policySchema': 'chrome.users.PluginVmAllowed',
        'value': {
          'pluginVmAllowed': true,
          'ackNoticeForPluginVmAllowedSetToTrue': true
        }
      },
      'updateMask': {
        'paths': [
          'pluginVmAllowed',
          'ackNoticeForPluginVmAllowedSetToTrue'
        ]
      }
    }
  ]
}" \
"https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

הגדרת מדיניות קבצים

בחלק מכללי המדיניות מופיעים השדות UploadedFile. תצטרכו להעלות לשרת ה-API את הקובץ שרוצים להגדיר בתור הערך של כללי המדיניות האלה, כדי לקבל כתובת URL לשימוש בבקשות BatchModify.

בדוגמה הזו נגדיר את chrome.users.Wallpaper על ידי העלאת קובץ JPEG.

העלאת הקובץ

בקשה

curl -X POST \
  -H "Content-Type: image/jpeg" \
  -H "Authorization: Bearer $TOKEN" \
  -T "/path/to/the/file" \
  "https://chromepolicy.googleapis.com/upload/v1/customers/$CUSTOMER/policies/files:uploadPolicyFile?policy_field=chrome.users.Wallpaper.wallpaperImage"

תשובה

תגובה מוצלחת צריכה לכלול את כתובת ה-URL לגישה לקובץ:

{
  "downloadUri": "https://storage.googleapis.com/chromeos-mgmt/0gjdgxs370bkl6/ChromeOsWallpaper/32ac50ab-b5ae-4bba-afa8-b6b443912897"
}

הגדרת מדיניות הקובץ

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        },
                policyValue: {
                        policySchema: "chrome.users.Wallpaper",
                        value: {
                          wallpaperImage: {downloadUri: "https://storage.googleapis.com/chromeos-mgmt/0gjdgxs370bkl6/ChromeOsWallpaper/32ac50ab-b5ae-4bba-afa8-b6b443912897"}
                          }
                        },
                updateMask: {paths: "wallpaperImage"}
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

תשובה

תשובה מוצלחת צריכה להיות ריקה.

{}