Forums

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

Why can't I create a repo using API with a Personal Access Token?

Dov Frankel
Contributor
April 17, 2019

I'm attempting to use the API to script repo creation, but I'm getting a 401 authorization error. I'm using basic HTTP authentication, with my username and a personal access token. I'm in the "administrators" group, which has Admin access to the project, and I specified Admin access for my personal access token. I'm using this URL:

https://<our server address>/rest/api/1.0/projects/EP/repos

I'm making a POST request with the Content-Type "application/json" and the body (though I tried with all 3 documented parameters and it didn't make a difference):

{
"name": "TestRepo"
}

I'm in BitBucket Server 5.15.0, and the GET request to the same URL using my Personal Access Token returns the list of projects. Also, using my regular password works as expected. This is the response I'm getting for the POST request authenticating with my token:

HTTP/1.1 401
Server: nginx/1.14.0
Date: Wed, 17 Apr 2019 22:24:00 GMT
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Connection: close
X-AREQUESTID: @1Q2IL9Zx1344x744323x0
X-ASESSIONID: 13r0hpv
X-ASEN: SEN-11784298
Set-Cookie: crowd.token_key=<redacted>; Domain=<redacted>; Path=/; HttpOnly
X-AUSERID: 53
X-AUSERNAME: dfrankel
Cache-Control: no-cache, no-transform
Vary: X-AUSERNAME,Accept-Encoding
WWW-Authenticate: OAuth realm="https%3A%2F%2F<our server address>"
X-Content-Type-Options: nosniff

{"errors":[{"context":null,"message":"You are not permitted to access this resource","exceptionName":"com.atlassian.bitbucket.AuthorisationException"}]}

1 answer

1 vote
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 22, 2019

Hello Dov,

While you have reported you’re an administrator (and there is no doubt there), this error is related to your user/token not having the proper permissions. You must ensure your permissions for the user/token are set to have PROJECT_ADMIN permissions for the parent project they’re accessing. More about the permission levels for the tokens may be found at Personal access tokens. Once you have set or ensured the user/token is assigned the proper permissions, please attempt your POST call again to the create repo endpoint.

Do let us know if you have the same issue again along with if you’re able to create the repo after the adjustment.

Regards,
Stephen Sifers

Dov Frankel
Contributor
April 22, 2019

Whoops. Repo permissions were Admin, but Project was set to Read. Thanks!

Like Stephen Sifers likes this
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 22, 2019

Very happy you're able to find the issue and resolve it quickly!

Do reach out again if you run into any more problems.

Regards,
Stephen Sifers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events