API for Environment & Tenant Mapping

Hi Team,

Warm Greetings !

I’m writing a function by using Octopus API, where I’m supposed to pass Environment name (Or ID) as input parameter and I’ll get all tenant name(s) associated to it as output.

Is there any straight forward way to fulfill this requirement(?).

Thanks in advance.

Vivek Rai

Hi @raivivek1989,

Thanks for getting in touch!

This should be fairly easy to retrieve the environment information.

/api/environments will return a list of your environments with name and ID fields included.

If you’re using the octopus.client then this will retrieve the same information

$apikey = 'API-LREN0HDYII3BMDXP5A6X8NF3TCY' # Get this from your profile
$OctopusUrl = 'http://localhost/' # Your Octopus Server address
# You can this dll from your Octopus Server/Tentacle installation directory or from
# https://www.nuget.org/packages/Octopus.Client/
Add-Type -Path 'Octopus.Client.dll'
# Set up endpoint and Spaces repository
$endpoint = new-object Octopus.Client.OctopusServerEndpoint $OctopusUrl, $APIKey
$repository = New-Object Octopus.Client.OctopusRepository $endpoint

I hope this helps.


Hi Paul,

Thanks for your response…

This is not what I looking for. Let me explain again…

I want to retrieve how many (with name n detail) Tenants are associated with given environment.

Please write me back if its not clear. Thanks in advance.

Vivek Rai

Hi @raivivek1989,

Apologies, it sounded like you already had a script written and just needed to pass in the environment information.

If you’re just getting started then I would recommend making use of the octopus.client. We have a repository of sample scripts that will help you get started here: https://github.com/OctopusDeploy/OctopusDeploy-Api/tree/master/Octopus.Client

You should be able to use the above script to retrieve the required environment ID and then perform a search of the tenants that match.

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