How to get latest version from rest api

How to get latest version of the package while downloading package from built-in feed using rest api call. Script provided on following link can be used to download a specific package. Kindly help in getting latest package downloaded i.e. recently created package.

You can search for the latest package version or a specific version. Here’s some example powershell to do both:

$ErrorActionPreference = "Stop";

# Define working variables
$octopusURL = ""
$octopusAPIKey = "API-KEY"
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }
$spaceName = "Default"
$packageId = "your-package-id"

$spaces = Invoke-RestMethod -Uri "$octopusURL/api/spaces?partialName=$([uri]::EscapeDataString($spaceName))&skip=0&take=100" -Headers $header 
$space = $spaces.Items | Where-Object { $_.Name -eq $spaceName }

# Get latest package version
$latestPackages = Invoke-RestMethod -Uri "$octopusURL/api/$($space.Id)/feeds/feeds-builtin/packages/versions?packageId=$($packageId)&take=1" -Headers $header 
$latestPackage = $latestPackages.Items | Select-Object -First 1

# Check for specific version of
$specificVersionPackages = Invoke-RestMethod -Uri "$octopusURL/api/$($space.Id)/feeds/feeds-builtin/packages/versions?packageId=$($packageId)&versionRange=$versionRange&take=1" -Headers $header 
$specificPackage = $specificVersionPackages.Items | Select-Object -First 1

You can them combine the above script with the example shown in our docs you linked to.

1 Like

Thank You mark.

Is their a way to get package version which is deployed on one of the tenant in some project?
I used “api/$(”

I am able to fetch the data. If i try getting latest release i am able to get it but i want latest release version which is deployed on tenants. Please let me know if i can get the latest deployed release version from any tenant which is inside some project. Thank You