Error - REST API Get Deployments with taskState

Hi team,

I’m trying to use /{baseSpaceId}/deployments to get the latest successful deployment of an environment.

I have narrowed the query down as much as I can, see below.
/api/Spaces-1/deployments?projects=Projects-661&environments=Environments-341&channels=Channels-882&take=1

The last step is to add the query string for taskState.
Unfortunately, as soon as I update the uri to below, it errors with “SQL Error 8003 - The incoming request has too many parameters.”
/api/Spaces-1/deployments?projects=Projects-661&environments=Environments-341&channels=Channels-882&taskState=Success&take=1

I tried other states like Failed and Canceled. They both worked fine. We do have a very large number of successful deployments though, over 10k+ in count.

It looks like the TAKE parameter is not considered when building the SQL query. By the look of it, the SQL query has all successful deployments.

Is there anything I can try to make this request work?

Hi @leonard.chu,

Thanks for reaching out, sorry to hear you’re having issues with the REST API!

We’ll start investigating this as I definitely feel there could be a bug here, however I wonder if for a workaround you could query the ‘dashboard’ endpoint for the information you need?

/api/Spaces-1/dashboard?highestLatestVersionPerProjectAndEnvironment=true

Feel free to let me know if you have any questions, I’ll keep you posted if I have any updates!

Hi @finnian.dempsey ,

Thanks for your reply.

The workaround above doesn’t serve well in my case as I need to latest successful deployment. The suggestion you provided would return a failed deployment.

I’m afraid I have to do this by retrieving x latest deployments, then loop through them in descending order to get the latest successful deployment.

Hi Leonard,

Thanks for getting back. I have a script here which will hopefully allow you to query the latest successful deployment to any particular environment and project. Hopefully it serves as a workaround while we continue to investigate the error in your initial message.

#Add-Type System.Web

##CONFIG Replace with your values
$octopusURL = "YourOctopusServer" #Octopus URL
$octopusAPIKey = "API-KEY" #Octopus API Key
$spaceName = "Name of target Space"
$environmentName = "EnvName"
$projectName = "ProjectName"

##PROCESS##
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }

$space = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/spaces/all" -Headers $header) | Where-Object {$_.Name -eq $spaceName}
$projects = (Invoke-RestMethod -Method Get -Uri "$octopusURL/api/$($space.Id)/projects?take=2000000" -Headers $header).items

$project = @($projects | Where-Object {$_.Name -eq $projectName})
$ProjectDashboardReleases = (Invoke-WebRequest $octopusURL/api/$($space.Id)/progression/$($project.Id) -UseBasicParsing -Method Get -Headers $header).content | ConvertFrom-Json

$environment = @($ProjectDashboardReleases.Environments | Where-Object {$_.Name -eq $environmentName})
$LastSuccessfulRelease = $ProjectDashboardReleases.Releases.Deployments.$($environment.Id) | ?{$_.state -eq "Success"} | select -First 1


Write-Output $LastSuccessfulRelease

Let me know if this works for you or if you continue to experience the same error.

Best regards,
Daniel

Hi @Daniel_Fischer ,

Thanks for your suggestion above.

I have tried progression call, however it doesn’t look quite clear to me as to how it works.

  • It has old releases that were already deleted by retention policies
  • It doesn’t have all releases that I can see on “Project” → “Releases” page in Octopus UI
  • The Wiki page does not have much details to assist

This should be fine now, as I’m able to get want I need with a combination of deployment, task and release calls.

Hi @leonard.chu,

Just stepping in for Daniel while he’s offline.

Great to hear you are able to get the info you need! We are still working on reproducing the SQL parameter issue and will make sure to keep you updated.

The progression endpoint is definitely lacking in documentation, I was able to find an old forum post discussing it however it seems to relate to the Prevent Release Progression feature.

I found the SwaggerUI endpoint had some decent information about what was being returned:

https://<octopusurl>/swaggerui/index.html → Progression

Feel free to reach out if you still have any questions!

Best Regards,