github-enterprise

GitHub Enterprise Download Asset


I want to download some assets from internal repositories by a simple batch script. So far I am able to see the releases and the asset informations, like "id", "name" and "browser_download_url".

I have created a user "builder" for this kind of jobs. The user is member of the repos and it has a token with Scope "repo".

I use curl for communication. With this curl command line I get a file that only contains JSON meta details of the asset

curl --ca-native --ssl-no-revoke -v --header "Accept: application/vnd.github.v3+json" --header "Authorization: Bearer MYTOKEN" -L --header "Accept: application/octet-stream" --output "C:\TARGET\LIB\ASSET.h" "https://HOST/api/v3/repos/ORGANIZATION/REPOSITORY/releases/assets/ASSET-ID"

When I use the "browser_download_url", read from the meta-info of the asset, using this command line

curl --ca-native --ssl-no-revoke -v --header "Accept: application/vnd.github.v3+json" --header "Authorization: Bearer MYTOKEN" -L --header "Accept: application/octet-stream" --output "C:\TARGET\LIB\ASSET.h" "https://HOST/ORGANIZATION/REPOSITORY/releases/download/TAG/ASSET.h"

I get a HTTP 406 repsonse.

I already have read the documentation here https://docs.github.com/de/enterprise-server@3.12/rest/releases/assets?apiVersion=2022-11-28 and wonder where my mistake is.

I also zipped the text-files I wanted to download to have real binary files, but that doesn't changed anything.

When I copy the "browser_download_url" into the browser, it downloads the file immediatly, with the expected content.

Any hints would be really appreciated.


Solution

  • FINALLY I did it!

    After struggeling with this for days here is what I found out:

    Use the API to get all releases, asset-id and the browser_download_url. To use the API with curl an authorization-header is needed. This header needs to be given as

    --header "Accept: application/vnd.github.v3+json" --header "Authorization: Bearer TOKEN"
    

    Now all answers from GitHub-Enterprise are formatted as JSON, I wasn't able to download any asset.

    To download an asset you need to use the browser_download_url given by the API queries for an asset. Also the headers need to change now to:

    --header "Accept: application/octet-stream" --header "Authorization: token TOKEN" 
    

    So to nail it:

    Both accept the same TOKEN created in GitHub for that specific user ...

    The TOKEN need the scope: repo

    Hope that helps others too