getting error message on endpoints setting permissions for repository repo_name 403

Richard Killeen August 25, 2023

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
                                                      

1 answer

1 accepted

0 votes
Answer accepted
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 27, 2023

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

Richard Killeen August 28, 2023

Hi @Syahrul  I am trying to post the permissions I have captured from a source workspace for all the repositories to a new workspace.

Richard Killeen August 28, 2023

@Syahrul would you know of any other way to transfer repository permissions?

Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 28, 2023

Hi @Richard Killeen 

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

Richard Killeen August 29, 2023

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 

Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 29, 2023

Hi @Richard Killeen 

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

Richard Killeen August 30, 2023

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 

Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 30, 2023

Hi @Richard Killeen 

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

Richard Killeen September 1, 2023

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? 

Richard Killeen September 1, 2023

I am using a GET method to capture the repositories.

Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 3, 2023

Hi @Richard Killeen 

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

Richard Killeen September 4, 2023

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. 

Richard Killeen September 4, 2023

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", [])

Richard Killeen September 4, 2023

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.

Like Syahrul likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events