List of remote repositories
Asked by Steven Burck:

I am writing a BASH script which needs to get remote information from Atlassian GIT. The information is a list of repositories in a given project. What I have to do to get this information currently is to make an application with a web browser which goes to that directory, wait for the page to load, then parse the results and strip out the unneeded information. Is there an API in which I could do this?


Answers:
author: Peter Van de Voorde
body: Hi [@Steven Burck](/t5/user/viewprofilepage/user-id/5347062) ,  

Welcome to the Atlassian Community, sounds like you need the Bitbucket REST API, check out this specific endpoint: <https://developer.atlassian.com/server/bitbucket/rest/v814/api-group-project/#api-api-latest-projects-projectkey-repos-repositoryslug-get>   

I believe that's what you're looking for.  

Cheers,  
Peter

comments: author: Steven Burck
body: Thanks very much Peter. I'm trying it now, but getting back

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

which seems pretty self-explanatory, but AFAIK I have rights there (trying to get the admin to check this, may take a while). I know that I can see the project and modify it in the browser. I see in the documentation that I only need **PROJECT_READ.**


author: Steven Burck
body: As far as the admin is concerned, I have read and write access to the project.


author: Peter Van de Voorde
body: Hey [@Steven Burck](/t5/user/viewprofilepage/user-id/5347062) ,  

Can you try calling any other API endpoint and see if those work? If not it might be that you're not authenticating properly when calling the API endpoint.   

Also to get the actual repository information you'll need REPO_READ permissions too.  

Cheers,  
Peter


author: Steven Burck
body: I'm doing a lot of experimentation, the problem is that it's on a secure server, so I'm retyping everything here, so (a) it goes slowly, and (b) I make mistakes, and so it goes even more slowly.

One of the problems is I'm unsure of what the {baseURL} should be. I tried both

<http://servername:7990/> (which results in the not permitted response)

and

<http://servername:7990/scm> (which results in a 404 response)

Here, the full command is

curl --request GET --url '<http://sername:7990/scm/rest/api/latest/projects/IPP2/repos>' --header 'Accept: application/json' (or without the /scm)

with the 404 response appears:

{"message":"null for uri: <http://servername:7990/rest/api/1.0/scm/rest/api/latest/projects/IPP2/repos>","status-code":404}

Note the duplication of 'rest/api' in the url of the response, I find that curious.

Without the scm the response was as in the previous answer (not permitted)

For a different endpoint, (<http://servername:7990'/scm/rest/api/latest/groups>) the results were exactly the same -

with scm, 404 with the url having the repeated rest/api in it, and without "not permitted"


author: Peter Van de Voorde
body: Interesting, but also frustrating.   

Does your admin see anything in the log files that might help you out?


author: Steven Burck
body: Sorry it took so long, my administrator was out and so I used Wireshark to see the differences between using the browser and curl. The different was username, which, when I added it to my curl request, went fine. I have to see how to go about setting up a netrc file with this data, as I really can't put it in the command. Thanks for the help.


Tags: bitbucket-server

server