Skip to content

How to get groups and projects for current user ? #2124

Answered by JohnVillalovos
dd-ssc asked this question in Q&A
Discussion options

You must be logged in to vote

To retrieve a user's projects would do something like this:

from gitlab import Gitlab
gitlab_token = '<snipped>'
gl = Gitlab(private_token=gitlab_token)
gl.users.get(USER_ID)
for index, project in enumerate(gl.users.projects.list(iterator=True)):
    print(f"{index}: {project!r} {project.web_url}")

https://docs.gitlab.com/ee/api/projects.html#list-user-projects

But as the Gitlab docs state this only retrieves projects located under the user's namespace. Not all projects that the user has access to.

Now to get all projects that the current user is a member of can do:

for index, project in enumerate(gl.projects.list(membership=True, iterator=True)):
    print(f"{index}: {project!r} {proje…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by JohnVillalovos
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #2123 on July 04, 2022 18:55.