Download released asset from private github repo

Viewed 1292

I'm trying to download a single added asset from a release in a private repository but all I get is a 404 response. the download url of the asset is https://github.com/<user>/<repo>/releases/download/20211022/file.json

I've tried several different methods of specifying the username and private access token but all give the same result. When I use the access token to access api.github.com then it seems to work.

I've tried the following formats in curl

curl -i -u <user>:<token> <url>
curl -i "https://<user>:<token>@github.com/ ...."
curl -i -H "Authorization: token <token>" <url>

I can download the source code (zip) from the release, but this has a different url: https://github.com/<user>/<repo>/archive/refs/tags/20211022.zip

What am I doing wrong?

1 Answers

As in the document here
You have to use url: /repos/{owner}/{repo}/releases/assets/{asset_id} not browser_download_url and set request header to accept application/octet-stream to download.
And don't forget to add Authorization header too.

Related