Using the Octopus Client to filter tasks

Hi there team,

Hope you are all doing great :slight_smile:

I’m trying to generate a report of tasks from .NET in the same way the Tasks page works on the UI.

I’m trying to generate from .NET the equivalent API call that is made whenever I apply these filters in the UI

What would the Octopus.Client version of that look like?

My first attempt was using the Repository.Tasks.FindMany() method, but that one (IIRC) paginates through all the tasks, which creates a huge overload.

Cheers,
Dalmiro

Hey Dalmiro, long time no see. I hope all is well!

So I found with the client it doesn’t do a good job of exposing that kind of specificity of what you are looking for in any of the repos. The good news is you can still use the client, but with a slight twist. You use the client.List function and pass in the parameters as a dynamic object.

I pulled this from: Cancel queued deployments - Octopus Deploy. It will find all the queued deployments.

The properties on the dynamic object match the parameters sent in via the API.

// Declare working varibles
var octopusURL = "http://octotemp";
var octopusAPIKey = "API-DY8544IVQCQX8JXCGNH4URENNY";
string spaceName = "default";

// Create repository object
var endpoint = new OctopusServerEndpoint(octopusURL, octopusAPIKey);
var repository = new OctopusRepository(endpoint);
var client = new OctopusClient(endpoint);

var space = repository.Spaces.FindByName(spaceName);
var repositoryForSpace = client.ForSpace(space);

var queuedDeployments = client.List<TaskResource>(repositoryForSpace.Link("Tasks"), new { states = "Queued", name = "Deploy", take = "50", skip = "0"});

foreach (var task in queuedDeployments.Items)
{
// Do Stuff!
}

I hope that helps!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.