When you are running jobs, you might want to update user permissions for multiple users.
You can do this by using the Databricks job permissions API (AWS | Azure | GCP) and a bit of Python code.
Instructions
- Copy the example code into a notebook.
- Enter the <job-id> (or multiple job ids) into the array arr[].
- Enter your payload{}. In this example, we are using the <username> and <permission> that we want to grant.
- Enter the <workspace-url> into the url field.
- Enter the <token> under Bearer.
- Run the notebook cell with the updated code.
If the update is successful, the code returns a response of 200 (OK).
Example code
%python import requests import json arr=[<job-id-1>,<job-id-2>] for j in arr : def requestcall(): payload = {"access_control_list": [{"user_name": "<username>","permission_level": "<permission>"}]} url='https://<workspace-url>/api/2.0/permissions/jobs/'+str(j) myResponse = requests.patch(url=url, headers={'Authorization': 'Bearer <token>'}, verify=True, data=json.dumps(payload)) print(myResponse.status_code) print(myResponse.content) # If the API call is successful, the response code is 200 (OK). if myResponse.ok: # Extracting data in JSON format. data = myResponse.json() return data requestcall()