Working directly with the Client

For some operations not available through repositories, it will be necessary to use the IOctopusClient type:

PowerShell
$connection = $repository.Client.Get($machine.Links["Connection"]);
C#
// Sync
var connection = repository.Client.Get(machine.Links["Connection"]);
 
// Async
var connection = await client.Get(machine.Links["Connection"]);

The entire API is accessible by traversing links - each resource carries a collection of links, like the Connection link on MachineResource shown above.

Always access objects by traversing the links; avoid using direct url segments, as they may change in the future.

To start traversing links, the IOctopusClient.RootDocument is provided:

PowerShell
$link = $repository.Client.RootDocument.Links["CurrentUser"].ToString()
$method = $repository.Client.GetType().GetMethod("Get").MakeGenericMethod([Octopus.Client.Model.UserResource])
$me = $method.invoke($repository.Client, @($link, $null))
C#
// Sync
var me = repository.Client.Get<UserResource>(repository.Client.RootDocument.Links["CurrentUser"]);
 
// Async
var me = await client.Get<UserResource>(client.RootDocument.Links["CurrentUser"])

(This is only an example. This common operation is also available via repository.Users.GetCurrent().)

Help us continuously improve

Please let us know if you have any feedback about this page.

Send feedback

Page updated on Sunday, January 1, 2023