Download ZIP file of private gitea repository

I can use the chrome browser to download the ZIP file of a private gitea repository after entering username and password.

I try to use curl to download the same ZIP file.

I followed gitea API:

and tried:

curl -XPOST -H "Content-Type: application/json"  -k -d '{"name":"test"}' -u username:password<username>/tokens
curl --request GET --url<username>/tokens

Both curls were successful.

Then I tried:

curl --location-trusted --user myusername:mypassword --request GET -H "Authorization: token 16c3e37d" -O --url

I got this file, its size is much smaller than the expected file size.
Its content, edited for brevity, is:

<form class="ui form" action="/user/login" method="post">
<input type="hidden" name="_csrf" value="MPetQDF">
<div class="required inline field">
  <label for="user_name">Username or Email Address</label>
  <input id="user_name" type="text" name="user_name" value="" autofocus required>

<div class="required inline field">
  <label for="password">Password</label>
  <input id="password" name="password" type="password" value="" autocomplete="current-password" required>


<a href="/api/swagger">API</a>

<script src="/assets/js/index.js?v=a30bc3"></script>

How to proceed further?

Please help.

The reason it dosn’t work is simply because gitea’s frontend and it’s API are seperated.
Meaning, when you authenticate via the API you are only allowed to use the API.

What you need is the /api/v1/repos/<owner>/<repo>/archive/<archive> endpoint.
So the correct curl would be:

curl -H "Authorization: token xxxx" -O<owner>/<repo>/archive/

(Note that the token needs to be the complete one, not the truncated one found in token_last_eight)

You can also see (and even test!) the API right from gitea’s frontend via the builtin swagger documentation, located at

1 Like