How to get file path? How to fetch a file?

I cannot get a file from our gitlab repository.

From the docs it follows that paths should be like:

curl --header "PRIVATE-TOKEN: <your_access_token>" ""

but in the GitLab UI I couldn’t manage to find ANYTHING like that.
The best I could find so far looks like this:

I searched carefully in the UI but there is no API links or paths to a file.
How do you manage to use it?


is the project ID which you need to pass into the API request URL. That can be seen in the project overview in the UI, or by searching/getting the project via API.

For the API request itself, the endpoint is constructed with /api/v4/projects/13083/repository/files/ and the file structure underneath.

If I navigate to a specific file, I know that /blob/main is the reference to the current branch main and everything after it represents the relative file path.

It is manual work though, and I try to avoid constructing URLs without first having searched and matched a pattern, e.g. fetching all files with the *.toml or *.md file suffix.

  1. Repository tree search
  2. Use file_path in the URL to fetch the raw content

I’m a fan of more programmatic approach with abstracting the API client to e.g. python-gitlab. I’ve created a quick example code snippet.

Works pretty good, never did that myself before.