Hi I am getting the following error message "Error setting permissions for repository repo_name 403 - This endpoint does not support token-based authentication" I am not using token based authorization. This is the method in the python script I use:
def set_repository_permissions(username, password, destination_workspace, repo_name, source_repo_permissions):
destination_repo_permissions_url = f"https://api.bitbucket.org/2.0/workspaces/{destination_workspace}/permissions/repositories/{repo_name}"
print(destination_repo_permissions_url)
headers = {
"Content-Type": "application/json",
}
for permission in source_repo_permissions:
response = requests.post(destination_repo_permissions_url, auth=(username,password), json=permission, headers=headers)
if response.status_code != 201:
print(f"Error setting permissions for repository {repo_name}: {response.status_code} - {response.text}")
print(f"Permissions set for repository {repo_name}.")
Is there a reason it returns that particular error message
G'day @Richard Killeen
May I know what are you trying to achieve with the following endpoint so we are on the same page?
The reason I ask this is because you are using "List a repository permissions for a workspace" API endpoint that only has a GET request. We don't have a POST request for this endpoint.
Regards,
Syahrul
Hi @Syahrul I am trying to post the permissions I have captured from a source workspace for all the repositories to a new workspace.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe what you are looking for is group-privileges Endpoint to add group permission to the existing repository.
I hope this helps.
Regards,
Syahrul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Syahrul thanks for the response not sure this will get me what I need as I need to transfer each individual user and their permissions within the repository to a new repository in a new workspace any help would be appreciated
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the clarification, and I apologize for any confusion.
While we don't currently offer a transfer repository API endpoint, we have a script here to guide you. You can customize this script to meet your specific requirements.
It's important to note that transferring a repository won't automatically transfer user permissions and groups. Therefore, you must manually recreate and reconfigure these settings in the new workspace.
I hope this helps.
Regards,
syahrul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Syahrul can you use the following endpoint in a script to set the permissions for a user in a repository ? https://developer.atlassian.com/cloud/bitbucket/rest/api-group-repositories/#api-repositories-workspace-repo-slug-permissions-config-users-selected-user-id-put
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The endpoint is designed to update existing groups within your workspace and repository rather than create new groups and permissions.
In short, the answer is no unless you already have groups created in your workspace and repository that need to be updated.
You should look into the old API v1.0 for group creation here.
Regards,
Syahrul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Syahrul I have transferred all permissions from all repositories to a json file using the endpoint: https://api.bitbucket.org/2.0/workspaces/{source_workspace}/permissions/repositories/{repo_name}
I notice it doesn't copy read permissions it sees the read permission as a write is there a reason for this or have you seen this issue before?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Based on my test, I can see the read permission when I call the following endpoint, so I wonder if the user did have the read access in the first place.
Can you navigate to the repository settings > repository permissions to verify that?
Regards,
Syahrul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Syahrul the user definitely has read permissions in the repository settings > repository permissions which changes to a write after making the call to the endpoint with the Get method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Syahrul I have included the python function when I print the permissions response it is showing as a write instead of a read.. def get_repository_permissions(username, password, source_workspace, repo_name):
source_repo_permissions_url = f"https://api.bitbucket.org/2.0/workspaces/{source_workspace}/permissions/repositories/{repo_name}"
headers = {
"Content-Type": "application/json",
}
response = requests.get(source_repo_permissions_url, auth=(username, password))
if response.status_code != 200:
print(f"Error getting permissions for repository {repo_name}: {response.status_code} - {response.text}")
return []
permissions_data = response.json()
print("Permissions Response:")
print(json.dumps(permissions_data, indent=4)) # Print the entire response for debugging
return permissions_data.get("values", [])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Syahrul I just realized that the user with the read permissions was part of a group with write permissions for the workspace and this setting was overriding the individual user permissions. There is no need to respond thanks for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.