Problem deleting a repo
Asked by ab36245:

I am experimenting with the bitbucket api to create a new repo.

When creating the repo the only value I set in the POST request was the scm:

```
{

  "scm": "git"

}
```

It seems to work fine, and the repo is both GETable via the api and visible through the web interface. However, when I go to delete it via the api I get an error:

```
{

  "type": "error",

  "error": {

    "message": "Something went wrong",

    "id": "89bd52cc05d4470a9087f23da8d3a23f"

  }

}
```

I also cannot delete the repo via the web interface. I get a similar error in a dialog box in the bottom left hand corner of the screen.

The error message is not very informative :-) The only hint I get that something is wrong with the repo is if I try to update the repository settings I get a message:

Please fix errors below {#toc-hId--1214954259}
----------------------------------------------

Main branch needs your attention

The value in the main branch section is:

Main branch  
master  
Select a valid choice. master is not one of the available choices.  
However there are no options available in the list to choose from. (This is actually the same as my other repos, all created through the web interface and which seem to work without a problem).

I assume that there is a permission (or some other) setting missing, but it is not clear to me what. I would very much like to be able to use the api to create repos, but do not want to create a string of repos which I can't then edit successfully.

Any thoughts as to what is wrong?

Thanks!


Answers:
author: Caroline R
body: Hi, [@ab36245](/t5/user/viewprofilepage/user-id/4489887)! Welcome to the community!

I reviewed the code you shared in your message and confirmed that it corresponds to the below error:

```
ProjectPrivacyException: A repository in a private project cannot be publicly visible.
```

So the repository you are trying to delete is set as public, but the project that has this repository is private. This is the cause of this issue.

In this case, you can set this repository as private by following the next steps and then try to delete the repo:

* Access the repository \> **Repository settings**;
* Under the **Repository details** section, find the "**This is a private repository**" option and check this box;
* Click **Save changes**.

Also, if you want to create a repository using the API and make it private, you can use the following request:

```
curl -X POST -u username:AppPassword -H "Content-Type: application/json" -d '{"scm": "git", "is_private":"true", "project": { "key": "{inform_the_project_key_here}" } }' https://api.bitbucket.org/2.0/repositories/{workspacename}/{repository_name}
```

I hope this helps, but do let me know if you have any questions.

Kind regards,  
Caroline

comments: author: ab36245
body: Hi [@Caroline R](/t5/user/viewprofilepage/user-id/3934006)

Thanks very much for the quick reply.

Your diagnosis is quite correct. But unfortunately the fix wasn't quite as easy as you described it.

tl;dr I **can** fix the problem, but only by going through the api.

Just in case you want the details...

If I GET the repo information via the API the response includes:

```
"is_private": false
```

This is totally consistent with what you suggest.

But, if I try to change that setting via the web app (via the repo's **Repository Settings \> Repository Details** screen as you suggest), the "This is a private repository" setting is turned on (ticked) but also disabled (grayed out):

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/162363i198F02B0A4889522/image-size/large?v=v2&px=999 "image.png")

I cannot change the setting. Obviously this is an artefact as it does not agree with the repos actual "is_private" value. I suspect that the UI is simply not allowing the repo's state to be changed because the project it is in is private.

I then thought that maybe I could temporarily make the project public, then change the access on the repo.

But if I go to the **Project settings** page for the relevant project the setting for privacy is also turned on (ticked) but disabled (grayed out):

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/162365i44DA6DA192A96B96/image-size/large?v=v2&px=999 "image.png")

So, because I have (unintentionally) created a public repo in a private project, I seem to be stuck! In this state I can't change the repo setting from public to private and I can't change the project setting from private to public!

This seems to be a bug in the web app, but originating from the fact that the api POST request allowed the creation of a public repo (by not specifying a value for "is_private") in a private project (by not specifying a project and having it default to the oldest project, which in my case is private).

However, you'll be pleased to know that the api also came to my rescue. If I update the repo via a PUT setting

```
{
  "is_private": true
}
```

this update works. Once that's done I **can** delete the repo.

So, a minor request. The API POST request probably shouldn't be able to create a repo in a state that cannot be manipulated via the web. A rejected request saying that I couldn't create a public repo in a private project would have been perfect in my case.

Thanks again for your help


author: Caroline R
body: Hi, [@ab36245](/t5/user/viewprofilepage/user-id/4489887)!

Thank you so much for sharing this information here, I really appreciate this.

I confirmed this really is a bug and for this reason, I raised the following bug request to fix this issue:

* <https://jira.atlassian.com/browse/BCLOUD-21389>

Our development team will post an update on the bug report when this is fixed. If you are not familiar with our Bug Request Policy, you can read more about it [here](https://confluence.atlassian.com/support/atlassian-cloud-bug-fix-policy-206865884.html).

You can add yourself as a watcher (by selecting the **Start watching this issue** link in the bug report) if you'd like to get notified via email on any updates and also select the **This affects my team** link to indicate you are affected by this issue.

Kind regards,  
Caroline


author: ab36245
body: Thanks [@Caroline R](/t5/user/viewprofilepage/user-id/3934006) I really appreciate your responsiveness and assistance


author: Caroline R
body: I'm glad to help, [@ab36245](/t5/user/viewprofilepage/user-id/4489887)!

Kind regards,  
Caroline


author: Saurabh Patwardhan
body: This is still an issue.

Unable to delete the repositories created using api.


author: Caroline R
body: Hi, [@Saurabh Patwardhan](/t5/user/viewprofilepage/user-id/4010556).

My suggestion would be that you create a separate question for your issue, providing details on the errors you see and also whether the problem occurs on Bitbucket Cloud or Bitbucket Server.

We generally encourage users to create a new question for their issue instead of posting on someone else's question because 1) the root cause and resolution may be different for each case 2) a question can become cluttered and difficult to follow if we try to troubleshoot multiple users' issues in it.

Please feel free to let me know if you have any questions.

Kind regards,  
Caroline


Tags: bitbucket-cloud

cloud