Working directly with the Client
Last updated
For some operations not available through repositories, it will be necessary to use the IOctopusClient
type:
$connection = $repository.Client.Get($machine.Links["Connection"]);
// 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:
$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))
// 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()
.)
Need support? We're here to help.