Download Package Endpoint
  • 08 Apr 2024
  • 3 Minutes to read
  • Dark
    Light
  • PDF

Download Package Endpoint

  • Dark
    Light
  • PDF

Article Summary

The Download Package is an endpoint in ProGet's Common Packages API that will download a package file.

GET /api/packages/«feed-name»/download

Request Specification

To download a package, simply GET to the URL with a feed name, package identifiers, and an appropriate API Key.

GET /api/packages/«feed-name»/download?«package-identifiers»

Unless you use a purl, the parameters required will vary by feedtype.

📄 Note

The package identifier you use must resolve to a single package, otherwise a 400 will be returned.

Downloading a NuGet Package requires the name (e.g. myNugetPackage) and version (e.g. 1.0.0):

GET /api/packages/MyNugetFeed/download?name=MyNugetPackage&version=1.0.0

Alternatively, you can use the purl:

GET /api/packages/MyNugetFeed/download?purl=pkg:nuget/MyNugetPackage@1.0.0

Downloading an NPM package requires the name (e.g. myNpmPackage) and version (e.g. 2.0.0), and optionally a scope (e.g. @myScope) that's specified without the at-symbol:

GET /api/packages/MyNpmFeed/download?group=myScope&name=myNpmPackage&version=2.0.0

Alternatively, you can use the purl:

GET  /api/packages/MyNpmFeed/download?purl=pkg:npm/my-scope/myNpmPackage@2.0.0

Downloading a Python Package requires the name (e.g. myPythonPackage), version (e.g. 3.0.0), and a URL-encoded qualifier with the filename (e.g. filename=myPythonPackage.3.0.0.tgz):

GET /api/packages/myPythonFeed/download?name=myPythonPackage&version=3.0.0&qualifier=filename%3DmyPythonPackage.3.0.0.tgz

Downloading a Debian Package requires the name (e.g. myDebianPackage), version (e.g. 4.0.0), component (e.g. main), and a URL-encoded qualifier with the architecture (e.g. arch=amd64):

POST /api/packages/MyDebianFeed/download?group=main&name=myDebianPackage&version=4.0.0&qualifier=arch%3Damd64

Response Specification

ResponseDetails
200 (Success)the package file as content
403 (Unauthorized API Key)indicates a missing, unknown, or unauthorized API Key; the package file will not download
404 (Package Not Found)indicates that the specified package does not exist
500 (Server Error)indicates an unexpected error; the body will contain the message and stack trace, and this will also be logged

Sample Usage Scripts

Download A Package (Curl)

This script will download version 3.0.3 of the GeneralUtils.NET package in the private-nuget feed.

api_key="a1b2c3d4e5"
output_file="C:/MyFiles/GeneralUtils.NET-3.0.3.nupkg"
base_url="https://proget.corp.local"
nuget_feed="private-nuget"
nuget_package="GeneralUtils.NET"
package_version="3.0.3"

curl_command="curl -o \"$output_file\" --header \"X-ApiKey: $api_key\" \"$base_url/api/packages/$nuget_feed/download?purl=pkg:nuget/$nuget_package@$package_version\""

eval $curl_command

Powershell: Download Latest Package (Powershell)

This script will download the latest stable (non-prerelease) version of the GeneralUtils.NET package in the private-nuget feed.

$apiUrl = "https://proget.corp.local"
$apiKey = "a1b2c3d4e5" 
$feedName = "private-nuget" 
$packageName = "GeneralUtils.NET"
$downloadPath = "C:\MyOrganizationFolder\GeneralUtilsPackages"
$queryUrl = "$apiUrl/api/packages/$feedName/latest?name=$packageName&stableOnly=true"

$overwritePrompt = $true # Set to $false if you don't want to prompt for overwriting

$response = Invoke-RestMethod -Uri $queryUrl -Method Get -Headers @{ "X-API-Key" = $apiKey }

if ($response -eq $null) {
    Write-Host "No package information found. Please check the feed and package name."
} else {
    $latestVersion = $response[0].version
    $downloadUrl = "$apiUrl/api/packages/$feedName/download?name=$packageName&version=$latestVersion"
    $outputFileName = "$downloadPath\$packageName-$latestVersion.nupkg"

    if (Test-Path $outputFileName) {
        if ($overwritePrompt) {
            $userInput = Read-Host "The file '$outputFileName' already exists. Do you want to overwrite it? (Y/N)"
            if ($userInput -eq "Y" -or $userInput -eq "y") {
                Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFileName -Headers @{ "X-API-Key" = $apiKey }
                Write-Host "Package downloaded and overwritten: $outputFileName"
            } else {
                Write-Host "Download canceled. The existing file remains: $outputFileName"
            }
        } else {
            Write-Host "The file '$outputFileName' already exists. Use -overwritePrompt $true to enable overwriting."
        }
    } else {
        Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFileName -Headers @{ "X-API-Key" = $apiKey }
        Write-Host "Package downloaded: $outputFileName"
    }
}

This will download the package to the folder C:\MyOrganizationFolder\GeneralUtilsPackages. If the file already exists the user will be prompted to overwrite the existing file or not.

Download All Packages (Python)

This script will download all versions of the GeneralUtils.NET package in the private-nuget feed.

import os
import requests

api_key = "a1b2c3d4e5"
feed_name = "private-nuget"
package_name = "GeneralUtils.NET"
base_url = "https://proget.corp.local"
target_directory = r"C:\MyOrganizationFolder\GeneralUtilsPackages"

if not os.path.exists(target_directory):
    os.makedirs(target_directory)

package_versions_url = f"{base_url}/api/packages/{feed_name}/versions?name={package_name}&apikey={api_key}"
package_versions_response = requests.get(package_versions_url)
package_versions = package_versions_response.json()

for version in package_versions:
    version_name = version["version"]
    download_url = f"{base_url}/api/packages/{feed_name}/download?name={package_name}&version={version_name}&apikey={api_key}"
    target_file = os.path.join(target_directory, f"{package_name}.{version_name}.nupkg")

    if os.path.exists(target_file):
        print(f"File '{target_file}' already exists.")
        user_input = input("Do you want to overwrite the existing file? (Y/N): ").strip().upper()
        if user_input != "Y":
            print(f"Skipping download of {package_name} version {version_name}.")
            continue

    response = requests.get(download_url)
    if response.status_code == 200:
        with open(target_file, 'wb') as file:
            file.write(response.content)
        print(f"Downloaded {package_name} version {version_name} to {target_file}")
    else:
        print(f"Failed to download {package_name} version {version_name}")

print(f"All versions of {package_name} have been downloaded to {target_directory}.")

This will download the all packages to the folder C:\MyOrganizationFolder\GeneralUtilsPackages. If the file already exists the user will be prompted to overwrite the existing file or not.


Was this article helpful?