Skip to content

Instantly share code, notes, and snippets.

@annextuckner
Created May 30, 2025 14:39
Show Gist options
  • Select an option

  • Save annextuckner/fe5d9ade573797e72b6cd77d90738473 to your computer and use it in GitHub Desktop.

Select an option

Save annextuckner/fe5d9ade573797e72b6cd77d90738473 to your computer and use it in GitHub Desktop.
from google.oauth2 import service_account
from googleapiclient.discovery import build
import json
def main():
# Authenticate the service account
scopes = ['https://www.googleapis.com/auth/chrome.management.policy']
admin_to_impersonate = ''
credentials = service_account.Credentials.from_service_account_file(
'acsa.json', scopes=scopes, subject=admin_to_impersonate
)
# Build the service for Chrome Policy API
service = build('chromepolicy', 'v1', credentials=credentials)
customer_id = 'my_customer' # Or your actual customer ID
org_unit_id = '' # Replace with your org unit ID
extension_id = 'kbfnbcaeplbcioakkpcpgfkobkghlhen' # Replace with your extension ID
body = {
"requests": [
{
"policyTargetKey": {
"targetResource": f"orgunits/{org_unit_id}",
"additionalTargetKeys": {
"app_id": f"chrome:{extension_id}"
}
},
"policyValue": {
"policySchema": "chrome.users.apps.InstallType",
"value": {
"appInstallType": "ALLOWED"
}
},
"updateMask": "appInstallType"
}
]
}
response = service.customers().policies().orgunits().batchModify(
customer=f"customers/{customer_id}",
body=body
).execute()
print(json.dumps(response, indent=2))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment