Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Created repository via API - creates personal

jagauthier November 16, 2020

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 Champion
November 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.

jagauthier November 16, 2020

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
AUG Leaders

Atlassian Community Events