To implement API with filter

Hi Team,

I’m looking for a option to retrieve deployment history detail by using API.
But API doesnt have any filter option, like date wise filter.

API - http://octopus.elims-ng.eurofins.local/api/deployments

Can you please help me with the syntax if its possible. Thanks

Hi @raivivek1989,

Thanks for getting in touch!

To be able to filter the results of the API, the easiest option is going to be to query it using octopus.client from Powershell. This will enable you to manipulate the results as desired.

For example, this sample script will return only deployments created since 1st January 2020

# You can this dll from your Octopus Server/Tentacle installation directory or from
# https://www.nuget.org/packages/Octopus.Client/
Add-Type -Path 'C:\Program Files\Octopus Deploy\Octopus\Octopus.Client.dll' 

$apikey = 'API-CMPCNOYGUU62FBUJF4GV9IVYG' # Get this from your profile
$octopusURI = 'http://localhost:80' # Your server address

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 
$repository = New-Object Octopus.Client.OctopusRepository $endpoint

$DateTime = [DateTime]"01/01/2020"

$repository.Deployments.FindAll() | Where-Object -Property Created -GT -Value $DateTime

We have a repository of useful scripts to get you started here: https://github.com/OctopusDeploy/OctopusDeploy-Api/tree/master/Octopus.Client

I hope this helps, please let me know if you have any further questions.

Best regards,
Paul