Update job permissions for multiple users

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 and a bit of Python code.

Instructions

  1. Copy the example code into a notebook.
  2. Enter the <job-id> (or multiple job ids) into the array arr[].
  3. Enter your payload{}. In this example, we are using the <username> and <permission> that we want to grant.
  4. Enter the <workspace-url> into the url field.
  5. Enter the <token> under Bearer.
  6. Run the notebook cell with the updated code.

If the update is successful, the code returns a response of 200 (OK).

Example code

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()