0 votes

Is it possible to add multiple members to a group in a singe call to the REST API? The example code only shows a single member. What would the data structure look like in that case?

by (60 points)

1 Answer

0 votes
by (3.6k points)

Hello,

There is no possibility to add multiple members in a single REST API request. You need to send a separate Add member request for each new member. For example, in PowerShell, you can iterate through an array of distinguished names and add members one by one like so:

$memberIdentifiers = @(
    "CN=John Smith,CN=Users,DC=example,DC=com",
    "CN=Mary Sue,CN=Users,DC=example,DC=com",
    "CN=John Doe,CN=Users,DC=example,DC=com"
) # TODO: modify me
$groupIdentifier = "CN=My Group,OU=Groups,DC=example,DC=com" # TODO: modify me

$baseUrl = "https://host.example.com/restApi"
$endpoint = "/api/directoryObjects/groupMembers"

# Request parameters
$requestUrl = $baseUrl + $endpoint
$requestHeaders = @{"Adm-Authorization" = "YOUR-SECURITY-TOKEN"}

# Make requests
foreach ($dn in $memberIdentifiers)
{
    $requestBody = ConvertTo-Json @{
        "group" = $groupIdentifier;
        "newMember" = $dn
    } 

    Invoke-RestMethod -Method POST -Headers $requestHeaders -Uri $requestUrl `
        -Body $requestBody -ContentType "application/json"
}

Group members are added one by one everywhere in Adaxes, even if you add multiple members in bulk in Administration console. This is done because business rules that trigger Before/after adding a member to a group need to capture each operation separately and perform their actions for each new member.

0

Ok, thank you for that detailed explanation that explains why it works the way it does. Thanks.

Related questions

0 votes
1 answer

For instance to execute a powershell script that enable MFA for all member in that group?

asked Jan 27, 2023 by samuel.anim-addo (20 points)
0 votes
1 answer

We have a 3rd party vendor that we are able to add users based on AD security groups. What I need to do is set a parameter for the number of available licenses and whenever ... the group is 495 I would like an email to trigger telling me to add more licenses.

asked Oct 12, 2022 by A_Pastor (70 points)
0 votes
1 answer

Hello, I have my OUs structured so each department we're working with has an OU for their service accounts under their department OU. e.g. OU=Service Accounts,OU=Sales,OU= ... add each new OU to the scheduled task but I was hoping for something more hands off.

asked Oct 19, 2015 by drew.tittle (810 points)
0 votes
1 answer

When configuring web page - under "Object Selection" - you can only choose 1 location (OU) when you select "Allow selecting only AD objects located under" - is there a way to have multiple OUs instead - perhaps using a LDAP filter?

asked Feb 2, 2021 by foleyjm (20 points)
0 votes
1 answer

We have a potentially complicated sitaution and so far I have no found a solution. Any suggestions will be greatly appreciated. We have specific security groups that ... or see any user details other than the memberships for these specific security groups.

asked Jan 2, 2023 by WannabeGuru (20 points)
3,326 questions
3,026 answers
7,727 comments
544,678 users