Direct download of branch archive with auth?

Heyo community,
I got a simple question that I can’t find an answer to.
I’m trying to download an entire branch as a tar.gz file. Normally you’d just go to https://gitlab.com/example/example/-/archive/main/example-main.tar.gz and download that file. However, the repository it’s in is private. So I made a deploy token and tried https://launcher:myToken@gitlab.com/example/example/-/archive/main/example-main.tar.gz, again with no success (it just prompts me to log in).

So, how to do it, assuming there is a way to do it at all?

Thanks in advance!

PS: The use case of this is a launcher downloading the source code for an internal app and then extracting it automatically. However, I don’t want to bother everyone to mess with git or send my access token for the API all around (it’s an electron app, so there’s no real way of hiding it.)

Hi @joloz :wave:

For your use case, I suggest using the Projects > Get file archive API endpoint.

To download only one branch, you can use the ?sha=<commit_sha> attribute with the sha that corresponds with the latest commit to that branch:

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.com/api/v4/projects/<project_id>/repository/archive?sha=<commit_sha>"

I hope you find this helpful. Let me know if this works for you!