I had similar issue and figured out to make it work. Here are the steps:
export access_token=$(curl -s -X POST -u "<client_id>:<client_secret>" \ https://bitbucket.org/site/oauth2/access_token \ -d grant_type=client_credentials -d scopes="repository" | jq --raw-output '.access_token')
Replace <client_id> and <client_secret> with your OAuth consumer credentials.
curl --request GET \ --url 'https://api.bitbucket.org/2.0/repositories///branch-restrictions' \ --header 'Authorization: Bearer '${access_token}'' \ --header 'Accept: application/json'
Replace and accordingly. It will print out JSON response of all available branch restrictions for the repository. Find the branch and restriction_id for which to make the next changes.
curl --request PUT \ --url 'https://api.bitbucket.org/2.0/repositories///branch-restrictions/<restriction_id>' \ --header 'Authorization: Bearer '${access_token}'' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{ "type": "branchrestriction", "users": [ { "type": "user", "username": "" } ], "groups": [] }'
Replace , , <restriction_id>, and as needed. Funny thing here is that, in username, you can actually specify the workspace name, which will add your workspace "user" to the restrictions and pushback will work as intended. Please let me know if you made it work, I'm happy to assist you on this, as I know how pain it was for me to figure it out.