How to allow public access to a repository via the REST API in Bitbucket Server
Summary
In some cases, a Bitbucket Administrator will be required to update the public access of repositories in bulk, and updating via the UI can become tedious and time-consuming.
This task can easily be accomplished by running a cURL command on a REST endpoint.
Environment
Bitbucket Server or Data Center
Solution
Note for personal repositories
The <project-key> will go by the pattern ~username
Example: John Doe (username: jdoe) created a repository named MyRepository.
- The project-key will be ~jdoe
- The reposlug will be myrepository
Allow public access to a repository
curl -u <username> --location --request PUT 'https://host:port/rest/api/latest/projects/<project-key>/repos/<reposlug>' \
--header 'Content-Type: application/json' \
--data-raw '{"public": true}'
Deny public access to a repository
curl -u <username> --location --request PUT 'https://host:port/rest/api/latest/projects/<project-key>/repos/<reposlug>' \
--header 'Content-Type: application/json' \
--data-raw '{"public": false}'
Reference
Further information on https://docs.atlassian.com/bitbucket-server/rest/<bitbucket-server-version>/bitbucket-rest.html