How to get a full list of repositories that a user is allowed to access?

断了今生、忘了曾经 提交于 2019-11-30 01:55:50

问题


I have found bitbucket api like:

https://bitbucket.org/api/2.0/repositories/{teamname}

But this link return 301 status (moved permanently to !api/2.0/repositories/{teamname}).

Ok, but this one returns status 200 with zero repositories.

I provide two parameters as user and password, but nothing seems changed.

So, can anybody answer how to get full list of private repositories that allowed to specific user?


回答1:


Atlassian Documentation - Repositories Endpoint provides a detail documentation on how to access the repositories.

The URL mentioned in bitbucket to GET a list of repositories for an account is:

GET https://api.bitbucket.org/2.0/repositories/{owner}

If you use the above URL it always retrieves the repositories where you are the owner. In order to retrieve full list of repositories that the user is member of, you should call:

GET https://api.bitbucket.org/2.0/repositories?role=member

You can apply following set of filters for role based on your needs.

To limit the set of returned repositories, apply the role=[owner|admin|contributor|member] parameter where the roles are:

  • owner: returns all repositories owned by the current user.
  • admin: returns repositories to which the user has explicit administrator access.
  • contributor: returns repositories to which the user has explicit write access.
  • member: returns repositories to which the user has explicit read access.

Edit-1:
You can make use of Bitbucket REST browser for testing the request/response.(discontinued)




回答2:


You should not use the API from the https://bitbucket.org/api domain.

Instead, you should always use https://api.bitbucket.org.

Now one reason you might be getting an empty result after following the redirect could be because some http clients will only send Basic Auth credentials if the server explicitly asks for them by returning a 401 response with the WWW-Authenticate response header.

The repositories endpoint does not require authentication. It will simply return the repos that are visible to anonymous users (which might well be an empty set in your case) and so clients that insist on a WWW-Authenticate challenge (there are many, including Microsoft Powershell) will not work as expected (note, curl always sends Basic Auth credentials eagerly, which makes it a good tool for testing).



来源:https://stackoverflow.com/questions/23490763/how-to-get-a-full-list-of-repositories-that-a-user-is-allowed-to-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!