baubleglue
New Contributor II

 

 

Solution you've submitted is a solution for different topic (permission to run job, the job still runs as the user in run_as_user_name field). Here is an example of changing "run_as_user_name"

Docs:
https://docs.databricks.com/api/azure/workspace/jobs/update (expand new_settings options)

 

import requests
import json
import logging

logging.basicConfig(
    format="[%(asctime)s %(levelname)s %(filename)s:%(lineno)s - %(funcName)s()] %(message)s",
    level=logging.INFO,
)


token = "dapi******-2"

new_settings = {
    "job_id": 123,
    "new_settings": {
        "run_as": {"user_name": "name@company.com"}
    }
}

data = json.dumps(new_settings)

logging.info("data=%s", data)

headers = {
    "Authorization": f"Bearer {token}",
    "Content-Type": "application/json",
}

logging.debug("headers=%s", headers)

resp = requests.post(
    url=f"https://<URL>/api/2.0/jobs/update",
    data=data, headers=headers
)

logging.info("resp=%s %s", resp, resp.text)