4

EDIT 2:

It's working I have added raw parameter Thanks a lot to Arty-chan.

curl --insecure --request GET --header 'PRIVATE-TOKEN: Y_F8YP3nUnFbzhxkQvgo' https://gitlabxxxxxxxxxxxxxxx/api/v4/projects/98/repository/files/src%2Fmain%2Fscript%2Fdeploiement%2Fsettings%2Frci%2Fsesameweb2.sh/raw?ref=master >> setting.sh

EDIT: Thanks to Arty-chan.

I cannot download the file but I have long output. How can I download my sesameweb2.sh file please ? The sh file should contain some export variable and if I check the content it's not the content of my actual file :(

{"file_name":"sesameweb2.sh","file_path":"src/main/script/deploiement/settings/rci/sesameweb2.sh","size":792,"encoding":"base64","content_sha256":"0ef870c1ebf9e0be5a5a976a4d3e5424a0b5752a75c67fe4b7744eb8fd6279d3","ref":"master","blob_id":"e3937fb8a25edd7a73bbbe5d6b2e267a4e404ef5","commit_id":"577c6c9ba661eb2726b5cd2095bc93bbd7eb3302","last_commit_id":"6921e0acd61d24066a3d680a5d77bd68f880e4d1","content":"IyEvdXNyL2Jpbi9lbnYgYmFzaApleHBvcnQgQU5UX0hPTUU9L3Vzci9hcGFjaGUvYXBhY2hlLWFudC0xLjkuNwpleHBvcnQgTUFWRU5fSE9NRT0vdXNyL2FwYWNoZS9hcGFjaGUtbWF2ZW4tMy4xLjEKZXhwb3J0IEpBVkFfSE9NRT0vdXNyL2phdmEvamRrMS43LjBfNzkKZXhwb3J0IFRPTUNBVF9JTlNUPWFwYWNoZS10b21jYXQtMzEKZXhwb3J0IE5PTV9XQVI9Y3J5c2FsaWQKZXhwb3J0IE5PTV9XQVJfMj1jcnlzYWxpZHdlYgpleHBvcnQgQ09NUFVURVJOQU1FPVMwMFNMUjIwMQpleHBvcnQgUkVGRVJFTlRJRUxfTkFNRT1zZXNhbWV3ZWIKZXhwb3J0IGdyb3VwaWQ9cGFjaWZpY2EuYXBwbGljYXRpb25zLiR7UkVGRVJFTlRJRUxfTkFNRX12MTIKZXhwb3J0IGFydGVmYWN0aWQ9JHtOT01fV0FSfQpleHBvcnQgYXJ0ZWZhY3RpZF8yPSR7Tk9NX1dBUl8yfQpleHBvcnQgYXBwX3ZlcnNpb249TEFURVNUCmV4cG9ydCBuZXh1c191cmw9aHR0cDovL3JlcG9zaXRvcnktbWFuYWdlci5wYWNpZmljYS5jcmVkaXQtYWdyaWNvbGUuZnIvbmV4dXMKZXhwb3J0IG5leHVzX3JlcG89cGFjaWZpY2Etc25hcHNob3RzLXJlY2V0dGUtaW5mby1sb2NhbApleHBvcnQgZW52aXJvbm5lbWVudD1yZWNldHRlSW5mb3JtYXRpcXVlCmV4cG9ydCBtYXZlbl9zZXR0aW5nc19wYXRoPS9tbnQvbmFzX3VzaWwvYXBwcy9CdWlsZFRvb2xzL21hdmVuX3NldHRpbmdzL3NldHRpbmdzX3JlY2V0dGVfaW5mb3JtYXRpcXVlX2xpbnV4LnhtbApleHBvcnQgYnVpbGRfYW50X25hbWU9YnVpbGRfJHtSRUZFUkVOVElFTF9OQU1FfS54bWwK"}

Cannot understand how using api to download with curl my file on gitlab.

here my url:

https://gitlabxxxxxxx/administration/gitlab/raw/master/src/main/script/deploiement/settings/rci/setting.sh

I have checked official website but cannot understand how it's works and which part I should replace:

curl --request GET --header 'PRIVATE-TOKEN: <your_access_token>' 'https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fmodels%2Fkey%2Erb/raw?ref=master'

I have tried but it's not working

curl --insecure --request GET --header 'PRIVATE-TOKEN: Y_F8YP3nUnFbzhxkQvgo' 'https://gitlabxxxxxxxxxx/api/v4/administration/gitlab/98/src/main/script/deploiement/settings/rci/sesameweb2.sh/app%2Fmodels%2Fkey%2Erb/raw?ref=master'

My project ID is : 98 I would like to download this setting.sh, I'am using gitlab-ce 12.6.4.

Thanks for help

rab
  • 133
  • 2
  • 13

2 Answers2

4

When following the docs, you need to follow the /projects/:id/repository/files/:file_path format for the link, so don't replace everything, just the pieces with : in front.

You also need to make sure that the file path is using URI encoding.

With the information that you have, it would look something like this:

https://gitlabxxxxxxxxxx/api/v4/projects/98/repository/files/src%2Fmain%2Fscript%2Fdeploiement%2Fsettings%2Frci%2Fsetting.sh?ref=master

Arty-chan
  • 2,572
  • 1
  • 19
  • 25
  • Thanks a lot for repply but it's doesn't work. curl --insecure --request GET --header 'PRIVATE-TOKEN: Y_F8YP3nUnFbzhxkQvgo' https://gitlab.XXXXXXXX/api/v4/projects/98/repository/files/src%2Fmain%2Fscript%2Fdeploiement%2Fsettings%2Frci%2Fsetting.sh?ref=master {"message":"404 File Not Found"} – rab Jan 21 '20 at 23:22
  • I have edited my my question. Can you please help me ? – rab Jan 21 '20 at 23:37
  • Ah yes, saving the file locally is a bit separate. Glad you figured it out! – Arty-chan Jan 22 '20 at 08:42
  • I you are using windows please change 'PRIVATE-TOKEN: Y_F8YP3nUnFbzhxkQvgo' by "PRIVATE-TOKEN: Y_F8YP3nUnFbzhxkQvgo". – rab Jan 23 '20 at 14:20
0
curl -k --request GET --header PRIVATE-TOKEN:"<PRIVATE-TOKEN>" https://<gitlab_url>/api/v4/projects/<id>/repository/files/<path_url_encoded>/raw?ref=master > <destination_path>

OR

refer official example:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fmodels%2Fkey%2Erb?ref=master"

Here: PRIVATE-TOKEN - enter your private token

path_url_encoded = Check here

destination_path - path where you want to download the file with filename

Check the Official Doc

Keval
  • 557
  • 10
  • 15