cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to set jobs permission with rest api

guostong
New Contributor III

create job with cli, but can not set the permission with cli,
have to use rest api to set permission:
https://docs.databricks.com/api/workspace/permissions/set

below is my command in windows to set permission:
curl -X PUT https://my-workspace-url.azuredatabricks.net/api/2.0/permissions/jobs/my-job-id^
-H "Authorization: Bearer my-personal-token" ^
-H "Content-Type: application/json" ^
--data "{\"access_control_list\":[{\"user_name\": \"xxx@company.com\", \"permission_level\": \"CAN_VIEW\"}]}"

I got below error message:
{"error_code":"INVALID_PARAMETER_VALUE","message":"The job must have exactly one owner."}

anybody have the experience?

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions

youssefmrini
Honored Contributor III
Honored Contributor III

 

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:

 

text
# 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.

View solution in original post

2 REPLIES 2

youssefmrini
Honored Contributor III
Honored Contributor III

 

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:

 

text
# 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.

guostong
New Contributor III

thank you, the new permission list should be a whole list, not the new permission

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!