API Active Directory user list

I have an AD group assigned to a Team. The AD group is part of the Members list of the team. Utilizing the Octopus Rest API, is there a way to retrieve the users that belong to the AD group?

Hi @dsteidler,

First of all, welcome to the Octopus forums!

Thanks for reaching out.

This is doable with our Rest API, but it will take a bit of logic and iteration.

The pseudocode(which will need some work and syntax fixing) should be something similar to:

$users = GET call on https://serverurl/api/users/all
foreach ($user in $users){
$teams = GET call on https://serverurl/api/users/$useridvariable/teams
foreach ($team in $teams){
if (external security group displayname -eq $desiredADGroup)
      $arrayofusers += $user
output $arrayofusers

For instance, here is a user with 2 teams, 1 added directly (everyone) and 1 added via AD (octopus administrators, added via domain group “domain admins”

    "IsDirectlyAssigned": true,
    "ExternalSecurityGroups": [],
    "SpaceId": null,
    "Id": "teams-everyone",
    "Name": "Everyone"
    "IsDirectlyAssigned": false,
    "ExternalSecurityGroups": [
        "Id": "S-1-5-21-407178236-1921851229-3779588435-512",
        "DisplayName": "Domain Admins",
        "DisplayIdAndName": false
    "SpaceId": null,
    "Id": "teams-administrators",
    "Name": "Octopus Administrators"

As always test any code/pseudo code we give you before putting into prod as it may not work for all scenarios.

Please let me know if that works for you or if you need further assistance.


Thank you, appreciate the solution.
Could be the version of Octopus that I am using, /teams was not valid.
/permissions was valid and has an appropriate teams array.
With that adjustment, the solution will provide necessary information.

1 Like

Hi @dsteidler,

You’re very welcome! Thanks for letting me know you got it working. Sorry that teams didn’t exist for you, you’re right it must be a versioning thing as I try to keep very close to the latest version on the box I work with.

Please reach out to us if you need help in the future and I hope you have a great weekend.


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