Can I update a bitbucket deployment environment to enable admin_only

I am trying to use this documentation to update the admin_only option under restrictions.

curl -X PUT \
  -u <username>:<app_password> \
  -H "Content-Type: application/json" \
  -d '{
        "restrictions": {
            "admin_only": true
        }
      }' \
  https://api.bitbucket.org/2.0/repositories/<workspace>/<repo_slug>/deployments_config/environments/<environment_uuid>

This is returning a 405 and the {"type": "error", "error": {"message": "Method not allowed"}} which I am guessing what I am trying is not possible.

Hi @JohnnyO,
I just came across this and wanted to provide an answer even if it’s been a few months.

It is possible to update the restrictions using the APIs.

To do so, you’ll need to update your example in the following way:

  • replace PUT with POST
  • add the /changes path to the REST API url
  • update the payload to be as follows (notice the additional change at the start:
'{
  "change" : {
       "restrictions": {
           "admin_only":true
        }
    }
}'

Based on your example, this is how the updated code will be:

curl -X POST \
  -u <username>:<app_password> \
  -H "Content-Type: application/json" \
  -d '{
            "change" : {
                "restrictions": {
                     "admin_only":true
                }
            }
        }' \
  https://api.bitbucket.org/2.0/repositories/<workspace>/<repo_slug>/deployments_config/environments/<environment_uuid>/changes

Hope this helps,
Caterina

1 Like

Thanks Caterina!

I’ll try this and get back to you!