4

I have a bitnami VM with gitlab 6.1.0.0 and I'm trying to get the files of a specific project from the rest API.

I tried to do something like this:

http://<my-git-lab-server>/api/v3/projects/12/repository/files?private_token=<my_token>

Of course 12 marks the project id which exists. I got as a response 404 - page not found (BTW - the customized 404 page of gitlab)

I saw in the documentation that you need to pass parameters. So I used tree to get the files, like this:

http://<my-git-lab-server>/api/v3/projects/12/repository/tree?private_token=<my_token>

And I got for example this file (along with other files):

[... some files here ... , {"name": "test.py", "type": "blob", "mode": "100644", "id": <some-id-here>}]

Then I tried the same url as before and added the file_path and ref parameters as described in the documentation and it looked like this:

http://<my-git-lab-server>/api/v3/projects/12/repository/files?file_path=test.py&ref=master&private_token=<my_token>

I also tried "test.py" (with quotations). I tried using master as ref as this file is found in the master branch. Hope that's what I should put there.

Anyway, still getting 404 not found. I'm not sure how to get the file correctly.

The task is to copy some projects content to a new gitlab server (of a different version as well) - if that changes anything.

user1997656
  • 532
  • 1
  • 6
  • 20

2 Answers2

1

You mention you're using Gitlab v6.1. According to the history of https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/repository_files.md the /api/v3/projects/{id}/repository/files end point arrived in version 6.6. It looks like the /api/v3/projects/{id}/repository/tree endpoint arrived in version 5.3. So to get the files API functionality, you'll need to upgrade Gitlab.

Steven V
  • 16,357
  • 3
  • 63
  • 76
0

Although it's not possible to use GET /projects/:id/repository/files on version 6.1, it's possible to download the file using GET /projects/:id/repository/blobs/:sha. Take a look here: https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/repositories.md

Wagner Francisco
  • 2,210
  • 1
  • 16
  • 15