Zachary Weeden
Zachary Weeden

Reputation: 121

Downloading Github release via API

I am trying to download a releases of a repo on my company's enterprise github server. I have proper authorization headers with an OAuth token and am able to get the response of releases endpoint. This particular repo has the zip and tarball of source code as well as a compiled executable. The built executable is what I'm attempting to download. The response of the release request looks like this with the browser_download_url key in the assets key being of interest.

{
    "url": "***/releases/1491",
    "assets_url": "***/releases/1491/assets",
    "upload_url": "***/releases/1491/assets{?name,label}",
    "html_url": "***/releases/tag/1.0.6",
    "id": 1491,
    "tag_name": "1.0.6",
    "target_commitish": "release-1.0.6",
    "name": "1.0.6",
    "draft": false,
    "prerelease": true,
    "created_at": "2017-10-03T15:51:25Z",
    "published_at": "2017-10-10T16:54:16Z",
    "assets": [
        {
            "url": "***/releases/assets/53",
            "id": 53,
            "name": "<program>.exe",
            "label": null,
            "content_type": "application/x-msdownload",
            "state": "uploaded",
            "size": 36023208,
            "download_count": 10,
            "created_at": "2017-10-10T17:40:32Z",
            "updated_at": "2017-10-10T17:40:32Z",
            "browser_download_url": "***/1.0.6/<program>.exe"
        }
    ],
    "tarball_url": "***/tarball/1.0.6",
    "zipball_url": "***/zipball/1.0.6",
    "body": "<description of release>"
}

However when I attempt to request the browser_download_url I get html for the sign in page in the content of the response as it is looking for further authentication.

response = session.get(release_endpoint_response.json()['assets'][0]['browser_download_url'], headers={'Authorization': 'token <personal_access_token>'}) 

My question is that is there any way to download from this link without needing to explicitly log in and simply using tokens and headers?
What is the best way to go about this? Are there any wrappers or libraries that could help me achieve this in a different way? Much obliged!

EDIT: Furthermore, it should be noted that when requesting the tarball and zip urls, the compressed source code files download fine. The issue here is that I have an unsuitable build environment so I wish to download the executable. It's interesting that I do not have the authentication issues with the zips as I do with the build exe.

Upvotes: 5

Views: 4677

Answers (1)

Zachary Weeden
Zachary Weeden

Reputation: 121

I believe to have found a solution here. Essentially I need to get the asset id of the desired release and then include the Accept header as application/octet-stream. Just get the id of the asset in the release endpoint for whichever release you want, set the header and then hit this endpoint: /repos/:owner/:repo/releases/assets/:id

Upvotes: 7

Related Questions