Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Created repository via API - creates personal

Edited

Greetings,

  I am trying to program a quick detection of a repository under a project and if that repo does not exist create it.

So, I use the API to check for its existence, and upon a 404 I create a POST (with pycurl) to

 /rest/api/1.0/projects/PROJECT/repos/toplevel

Where toplevel is an existing repo.

The payload is:

{"name": "newrepo",

"scmID": "git",

"forkable": true}

 

I then POST this to

 /rest/api/1.0/projects/PROJECT/repos/toplevel

Expecting a new repo in toplevel/newpo.

 

Instead, a new repo is created in my personal area:

(The POST shows me the location)

/rest/api/1.0/projects/~USERNAME/repos/newrepo

 

I don't understand the redirection.

I have attempted to use this documentation along with examples I've found in these forums.

https://docs.atlassian.com/bitbucket-server/rest/7.7.1/bitbucket-rest.html#idp173

 

 

1 answer

1 accepted

0 votes
Answer accepted
Hana Kučerová Community Leader Nov 16, 2020

Hi @jagauthier ,

please try to skip toplevel repository in both requests.

1) check, if repository newrepo exist

GET /rest/api/1.0/projects/PROJECT/repos/newrepo

2) if not, create new newrepo repository

POST /rest/api/1.0/projects/PROJECT/repos

with payload

{
    "name": "My repo",
    "scmId": "git",
    "forkable": true
}

You also need to have PROJECT_ADMIN permission for the project PROJECT.

I see the issue.  I was trying to create a repo inside a repo.  Thanks for pointing it out!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,776 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you