Search code examples
gitgitlabgitlab-api

GitLab API - retrieve repository files


I have the following GitLab structure

Project-X
   - Repository-1
        - FileFoder-A
             - File-1
             - File-2
        - File-3
   - Repository-2
        - FileFoder-B
             - File-1
             - File-2
        - File-3

I am trying to fetch all files under Project-X/Repository-A using GitLab API v4.

I have tried the following:

https://gitlab.xx.local/api/v4/<project-x-id>/repository/<repository-A-id>/archive

But, it returns a 404.


Solution

  • There seems to be some confusion with the project structure. GitLab has a one to one relationship between projects and repositories. It's not possible that 'Project-X' has two repositories. Maybe you have a group with multiple projects?

    In any case, the API endpoint is not quite right, either. It should be something like https://gitlab.xx.local/api/v4/projects/<project-x-id>/archive. See GitLab API documentation for the repository file archive endpoint for more details.