This error message occurs because the Databricks REST API requires that every job have exactly one owner. When you try to set permissions using the API, you are required to specify the owner of the job using the owner field in the job metadata.
To resolve this issue, you need to make sure that the job has exactly one owner specified in the job metadata. You can update the job metadata using the Databricks CLI or API. Here is an example of how to update the job metadata using the Databricks API:
# set variables
TOKEN="<databricks-token>"
JOB_ID="<job-id>"
USERNAME="<username>"
# get current job metadata
JOB_META=`curl -s -X GET -H "Authorization: Bearer ${TOKEN}" "https://<databricks-instance>/api/2.0/jobs/get?job_id=${JOB_ID}"`
# parse job metadata
JOB_META_JSON=$(echo "${JOB_META}" | jq '.job')
# set owner in job metadata
JOB_META_JSON=`echo "${JOB_META_JSON}" | jq ".owner_username=\"${USERNAME}\""`
# update job metadata
curl -s -X POST -H "Authorization: Bearer ${TOKEN}" "https://<databricks-instance>/api/2.0/jobs/reset" \
-d "{\"job_id\": \"${JOB_ID}\", \"new_settings\": ${JOB_META_JSON}}"
This script uses the curl command and the jq command-line JSON processor to retrieve the current job metadata, add the specified owner to the job metadata, and then update the job with the new metadata.
Replace <databricks-token> with your Databricks token, <job-id> with the ID of your job, and <username> with the username of the owner you want to set. This script will update the job metadata to set <username> as the sole owner of the job.
After setting the owner in the job metadata, you should be able to set permissions using the Databricks REST API without encountering the "The job must have exactly one owner." error message.