REST API to disable fork

Greetings

Is there any REST API call to disable the fork for a repository in Bitbucket cloud ?

Thanks !

Welcome to the Atlassian developer community, @KotaSreenivasaShrava.

Yes, you can disable fork on a repository using PUT /2.0/repositories/{workspace}/{repo_slug}. You will need to send an attribute for fork_policy like:

{
  fork_policy: no_forks
}

The options come from the following enumeration:

  • allow_forks : unrestricted forking
  • no_public_forks : restrict forking to private forks (forks cannot be made public later)
  • no_forks : deny all forking
1 Like

Hi - Thanks for quick reply. I am executing this and its not working. Am I doing anything wrong?

curl --request PUT --user username:apppassword https://api.bitbucket.org/2.0/repositories/workspacename/sample --data ‘{fork_policy: no_forks}’

Could you share the response?

There was no response. It exits without any error or success message

I realized the example that I provided you isn’t valid JSON. I’m not sure how I forgot the double quotes:

{
  "fork_policy": "no_forks"
}

However, I tried with both double quotes and without and I still get a response from Bitbucket. It sounds like something is blocking your network access to the Bitbucket API.