getting error message on endpoints setting permissions for repository repo_name 403
Asked by Richard Killeen:

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](https://api.bitbucket.org/2.0/workspaces/%7Bdestination_workspace%7D/permissions/repositories/%7Brepo_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  


Answers:
author: Syahrul
body: G'day [@Richard Killeen](/t5/user/viewprofilepage/user-id/4073699)

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](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-workspaces/#api-workspaces-workspace-permissions-repositories-repo-slug-get)" API endpoint that only has a GET request. We don't have a POST request for this endpoint.

Regards,  
Syahrul

comments: author: Richard Killeen
body: Hi [@Syahrul](/t5/user/viewprofilepage/user-id/744536) I am trying to post the permissions I have captured from a source workspace for all the repositories to a new workspace.


author: Richard Killeen
body: [@Syahrul](/t5/user/viewprofilepage/user-id/744536) would you know of any other way to transfer repository permissions?


author: Syahrul
body: Hi [@Richard Killeen](/t5/user/viewprofilepage/user-id/4073699)

I believe what you are looking for is [group-privileges Endpoint](https://support.atlassian.com/bitbucket-cloud/docs/group-privileges-endpoint/) to add group permission to the existing repository.

I hope this helps.

Regards,  
Syahrul


author: Richard Killeen
body: Hi [@Syahrul](/t5/user/viewprofilepage/user-id/744536) 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


author: Syahrul
body: Hi [@Richard Killeen](/t5/user/viewprofilepage/user-id/4073699)

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](https://bitbucket.org/bbcloud-support-scripts/bulk-transfer-repositories/src/master/) 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


author: Richard Killeen
body: Hi [@Syahrul](/t5/user/viewprofilepage/user-id/744536) 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>


author: Syahrul
body: Hi [@Richard Killeen](/t5/user/viewprofilepage/user-id/4073699)

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.](https://support.atlassian.com/bitbucket-cloud/docs/groups-endpoint/)

Regards,  
Syahrul


author: Richard Killeen
body: Hi [@Syahrul](/t5/user/viewprofilepage/user-id/744536) 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?


author: Richard Killeen
body: I am using a GET method to capture the repositories.


author: Syahrul
body: Hi [@Richard Killeen](/t5/user/viewprofilepage/user-id/4073699)

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


author: Richard Killeen
body: Hi [@Syahrul](/t5/user/viewprofilepage/user-id/744536) 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.


author: Richard Killeen
body: Hi [@Syahrul](/t5/user/viewprofilepage/user-id/744536) 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", \[\])


author: Richard Killeen
body: Hi [@Syahrul](/t5/user/viewprofilepage/user-id/744536) 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.


Tags: bitbucket-cloud

cloud