Search directory in Adaxes 2021.1

Retrieves directory objects that fit the specified search criteria. This request can be used to retrieve business units.

GET ~/api/directoryObjects/search?<parameters>

This request is deprecated and should only be used in Adaxes 2021.1. In newer versions, use the Search directory request instead.

Query parameters

  • Name

  • Required

  • Type

  • Description

  • baseObject

  • False

  • string

  • The identifier of the container, organizational unit, or domain to search in. You can use:

     Distinguished name (DN)
    # Example
    CN=Users,DC=example,DC=com
    
     Globally unique identifier (GUID)
    # Example
    7a4267ce-d354-44e7-8bd6-c681f1284a41
    

    To search everywhere i.e. in all managed domains, don't specify this parameter in the request.

    To search for business units, specify wkobj:BusinessUnitsContainer, the well-known business unit container, as the parameter value.

  • oneLevel

  • False

  • bool

  • Set to true to only search across immediate children of the base object. If not specified, Adaxes will seacrh across the entire subtree of the base object. This parameter has no effect if the base object is not specified.

  • filter

  • False

  • string

  • Specify the search criteria as the parameter value. Only the objects that fit the criteria will be retrieved. The following values can be used:

    • An LDAP filter e.g. (&(objectCategory=person)(department=Sales)).
    • LockedOutAccounts — to retrieve locked user accounts.
    • TotpEnrolledAccounts — to retrieve users who activated a mobile authenticator app in Adaxes.

    If not specified, all objects located under the base object will be retrieved.

  • properties

  • False

  • string

  • A comma-separated list of LDAP property names without whitespaces e.g. manager,department. Each object in search results will contain the values of specified properties. If not specified, objects will be retrieved with the default property set.

     Default property set
    • guid
    • dn
    • displayName
    • objectType
    • objectTypeCode
    • domainName
  • sizeLimit

  • False

  • integer

  • The maximum number of objects to retrieve. Cannot exceed 1000. If not specified, the first 1000 objects that match the search criteria will be retrieved.

Request headers

  • Name

  • Required

  • Description

  • Adm-Authorization

  • True

  • Specify the security token obtained during authentication.

Request body

Do not send a body with this request.

Responses

  • If successful, returns 200 OK status code and an array of directory objects in the response body.
  • If successful, and there are no objects to retrieve, returns 200 OK status code and an empty array in the response body.
  • If unsuccessful, returns one of the common HTTP error codes and an error description in the response body.

The response will include only the objects that the authenticated user has the permissions to view. All permissions in Adaxes are granted by security roles.

Examples

 Example 1 – Find a user with a specific employee ID

The following code sample searches for a user with a specific employee ID in all managed domains.

Request

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

# Request parameters
$requestUrl = $baseUrl + $endpoint 
$requestHeaders = @{"Adm-Authorization" = YOUR-SECURITY-TOKEN}
$queryParams = @{
    "filter" = "(employeeId=MyId12345)";
    "properties" = "employeeId"
}    

# Make request
Invoke-RestMethod -Method GET -Headers $requestHeaders -Uri $requestUrl -Body $queryParams
C#
using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        const string baseUrl = "https://host.example.com";
        const string endpoint = "/restApi/api/directoryObjects/search";

        // Request parameters
        string ldapFilter = HttpUtility.UrlEncode("(employeeId=MyId12345)");
        const string propertiesToGet = "employeeId"
        UriBuilder requestUrl = new()
        {
            Host = baseUrl + endpoint,
            Query = $"?filter={ldapFilter}" + $"&properties={propertiesToGet}"
        };

        // Initialize HTTP client
        using HttpClient client = new();
        client.DefaultRequestHeaders.Add("Adm-Authorization", YOUR-SECURITY-TOKEN);

        // Make request
        string response = await client.GetStringAsync(requestUrl.ToString());
        Console.WriteLine(response);
    }
}
cURL
curl  --header 'Adm-Authorization: YOUR-SECURITY-TOKEN' \
--get -X GET 'https://host.example.com/restApi/api/directoryObjects/search' \
--data-urlencode 'filter=(employeeId=MyId12345)' \
--data-urlencode 'properties=employeeId'
node.js
var https = require('https');

// Request parameters
var ldapFilter = encodeURIComponent("(employeeId=MyId12345)");
var propertiesToGet = encodeURIComponent("employeeId");
var requestPath = "/restApi/api/directoryObjects/search"
    + `?filter=${ldapFilter}`
    + `&properties=${propertiesToGet}`;

var options = {
    'method': 'GET',
    'hostname': 'host.example.com',
    'path': requestPath,
    'headers': {'Adm-Authorization': 'YOUR-SECURITY-TOKEN'}
};

// Make request
var req = https.request(options, res => {
    var data = [];

    res.on("data", chunk => {
        data.push(chunk);
    });

    res.on("end", () => {
        var body = Buffer.concat(data);
        console.log(body.toString());
    });

    res.on("error", error => {
        console.error(error);
    });
});
req.end();
Python
import requests
import json

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

# Request parameters
requestUrl = baseUrl + endpoint
requestHeaders = {"Adm-Authorization": YOUR-SECURITY-TOKEN}
queryParams = {
    "filter": "(employeeId=MyId12345)",
    "properties": "employeeId"
}   

# Make request
request = requests.get(requestUrl, headers=requestHeaders, params=queryParams)
response = json.loads(request.content)
print(response)

Response

HTTP Status code: 200 OK
Response body:

[
    {
        "accountStatus": {
            "isDisabled": false,
            "isLocked": false,
            "expirationDate": null
        },
        "passwordStatus": {
            "whenChanged": "2020-09-03T14:18:48.974886Z",
            "expirationStatus": 0,
            "expirationDate": "2023-05-30T14:18:48.974886Z"
        },
        "guid": "13ce39d7-183d-41d7-9a6e-ad1ba85b4be3",
        "dn": "CN=Nick Johnston,OU=Sales,DC=example,DC=com",
        "displayName": "Nick Johnston",
        "objectType": "user",
        "objectTypeCode": 2,
        "domainName": "example.com",
        "properties": {
            "employeeId": [
                "MyId12345"
            ]
        }
    }
]
 Example 2 – Find computers with no owner in a specific OU

The following code sample searches in a specific OU for computers not managed by anyone.

Request

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

# Request parameters
$requestUrl = $baseUrl + $endpoint
$requestHeaders = @{"Adm-Authorization" = YOUR-SECURITY-TOKEN}
$queryParams = @{
    "baseObject" = "OU=My Organizational Unit,DC=example,DC=com";
    "filter" = "(&(objectCategory=computer)(!(managedBy=*)))";
    "oneLevel" = $true  
}

# Make request
Invoke-RestMethod -Method GET -Headers $requestHeaders -Uri $requestUrl -Body $queryParams
C#
using System;
using System.Web;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        const string baseUrl = "https://host.example.com";
        const string endpoint = "/restApi/api/directoryObjects/search";
        
        // Request parameters
        string baseObject = HttpUtility.UrlEncode("OU=My Organizational Unit,DC=example,DC=com");
        string ldapFilter = HttpUtility.UrlEncode("(&(objectCategory=computer)(!(managedBy=*)))");
        UriBuilder requestUrl = new()
        {
            Host = baseUrl + endpoint,
            Query = $"?baseObject={baseObject}" + $"&filter={ldapFilter}" + "&oneLevel=true"
        };

        // Initialize HTTP client
        using HttpClient client = new();
        client.DefaultRequestHeaders.Add("Adm-Authorization", YOUR-SECURITY-TOKEN);

        // Make request
        string response = await client.GetStringAsync(requestUrl.ToString());
        Console.WriteLine(response);
    }
}
cURL
curl  --header 'Adm-Authorization: YOUR-SECURITY-TOKEN' \
--get -X GET 'https://host.example.com/restApi/api/directoryObjects/search' \
--data-urlencode 'baseObject=OU=My Organizational Unit,DC=example,DC=com' \
--data-urlencode 'filter=(&(objectCategory=computer)(!(managedBy=*)))' \
--data-urlencode 'oneLevel=true'
node.js
var https = require('https');

// Request parameters
var baseObject = encodeURIComponent("OU=My Organizational Unit,DC=example,DC=com");
var ldapFilter = encodeURIComponent("(&(objectCategory=computer)(!(managedBy=*)))");
var requestPath = "/restApi/api/directoryObjects/search"
    + `?baseObject=${baseObject}`
    + `&filter=${ldapFilter}`
    + "&oneLevel=true";

var options = {
    'method': 'GET',
    'hostname': 'host.example.com',
    'path': requestPath,
    'headers': {'Adm-Authorization': 'YOUR-SECURITY-TOKEN'}
};

// Make request
var req = https.request(options, res => {
    var data = [];

    res.on("data", chunk => {
        data.push(chunk);
    });

    res.on("end", () => {
        var body = Buffer.concat(data);
        console.log(body.toString());
    });

    res.on("error", error => {
        console.error(error);
    });
});
req.end();
Python
import requests
import json

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

# Request parameters
requestUrl = baseUrl + endpoint
requestHeaders = {"Adm-Authorization": YOUR-SECURITY-TOKEN}
queryParams = {
    "baseObject": "OU=My Organizational Unit,DC=example,DC=com",
    "filter": "(&(objectCategory=computer)(!(managedBy=*)))",
    "oneLevel": True
}   

# Make request
request = requests.get(requestUrl, headers=requestHeaders, params=queryParams)
response = json.loads(request.content)
print(response)

Response

HTTP Status code: 200 OK
Response body:

[
    {
        "computerType": 1,
        "accountStatus": {
            "isDisabled": false,
            "isLocked": false,
            "expirationDate": null
        },
        "passwordStatus": {
            "whenChanged": "2020-10-20T08:14:20.025405Z",
            "expirationStatus": 1,
            "expirationDate": null
        },
        "guid": "f722deef-9d4c-4b09-8ec3-4a40cf1a31d8",
        "dn": "CN=COMPUTER1,OU=My Organizational Unit,DC=example,DC=com",
        "displayName": "COMPUTER1",
        "objectType": "computer",
        "objectTypeCode": 4,
        "domainName": "example.com",
        "properties": {}
    },
    {
        "computerType": 0,
        "accountStatus": {
            "isDisabled": false,
            "isLocked": false,
            "expirationDate": null
        },
        "passwordStatus": {
            "whenChanged": "2020-11-06T04:03:59.1758971Z",
            "expirationStatus": 1,
            "expirationDate": null
        },
        "guid": "9c8163f3-1d97-44b7-867e-2110f8e629db",
        "dn": "CN=COMPUTER2,OU=My Organizational Unit,DC=example,DC=com",
        "displayName": "COMPUTER2",
        "objectType": "computer",
        "objectTypeCode": 4,
        "domainName": "example.com",
        "properties": {}
    },
    {
        "computerType": 1,
        "accountStatus": {
            "isDisabled": false,
            "isLocked": false,
            "expirationDate": null
        },
        "passwordStatus": {
            "whenChanged": "2020-10-24T22:49:34.2660542Z",
            "expirationStatus": 1,
            "expirationDate": null
        },
        "guid": "8c3848f2-2008-432b-a1a9-942b5dff33ac",
        "dn": "CN=COMPUTER3,OU=My Organizational Unit,DC=example,DC=com",
        "displayName": "COMPUTER3",
        "objectType": "computer",
        "objectTypeCode": 4,
        "domainName": "example.com",
        "properties": {}
    }
]
 Example 3 – Find all security groups with a specific name prefix

The following code sample retrieves all security groups whose name starts with My in all domains.

Request

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

# Request parameters
$requestUrl = $baseUrl + $endpoint
$requestHeaders = @{"Adm-Authorization" = YOUR-SECURITY-TOKEN}
$queryParams = @{"filter" = "(&(groupType:1.2.840.113556.1.4.803:=2147483648)(name=My*))"}

# Make request
Invoke-RestMethod -Method GET -Headers $requestHeaders -Uri $requestUrl -Body $queryParams
C#
using System;
using System.Web;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        const string baseUrl = "https://host.example.com";
        const string endpoint = "/restApi/api/directoryObjects/search";

        // Request parameters
        string ldapFilter = HttpUtility.UrlEncode(
            "(&(groupType:1.2.840.113556.1.4.803:=2147483648)(name=My*))");
        UriBuilder requestUrl = new()
        {
            Host = baseUrl + endpoint,
            Query = $"?filter={ldapFilter}"
        };

        // Initialize HTTP client
        using HttpClient client = new();
        client.DefaultRequestHeaders.Add("Adm-Authorization", YOUR-SECURITY-TOKEN);

        // Make request
        string response = await client.GetStringAsync(requestUrl.ToString());
        Console.WriteLine(response);
    }
}
cURL
curl  --header 'Adm-Authorization: YOUR-SECURITY-TOKEN' \
--get -X GET 'https://host.example.com/restApi/api/directoryObjects/search' \
--data-urlencode 'filter=(&(groupType:1.2.840.113556.1.4.803:=2147483648)(name=My*))'
node.js
var https = require('https');

// Request parameters
var ldapFilter = encodeURIComponent("(&(groupType:1.2.840.113556.1.4.803:=2147483648)(name=My*))");
var requestPath = "/restApi/api/directoryObjects/search"
    + `?filter=${ldapFilter}`;

var options = {
    'method': 'GET',
    'hostname': 'host.example.com',
    'path': requestPath,
    'headers': {'Adm-Authorization': 'YOUR-SECURITY-TOKEN'}
};

// Make request
var req = https.request(options, res => {
    var data = [];

    res.on("data", chunk => {
        data.push(chunk);
    });

    res.on("end", () => {
        var body = Buffer.concat(data);
        console.log(body.toString());
    });

    res.on("error", error => {
        console.error(error);
    });
});
req.end();
Python
import requests
import json

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

# Request parameters
requestUrl = baseUrl + endpoint
requestHeaders = {"Adm-Authorization": YOUR-SECURITY-TOKEN}
queryParams = {"filter": "(&(groupType:1.2.840.113556.1.4.803:=2147483648)(name=My*))"}   

# Make request
request = requests.get(requestUrl, headers=requestHeaders, params=queryParams)
response = json.loads(request.content)
print(response)

Response

HTTP Status code: 200 OK
Response body:

[
    {
        "groupType": 0,
        "groupScope": 2,
        "membershipType": 0,
        "guid": "673017e7-3ce4-4862-9355-969bec56100f",
        "dn": "CN=My VPN Group,OU=Groups,DC=example,DC=com",
        "displayName": "My VPN Group",
        "objectType": "group",
        "objectTypeCode": 3,
        "domainName": "example.com",
        "properties": {}
    }
]
 Example 4 – Retrieve all locked users from a specific domain

The following code sample retrieves all locked user accounts that belong to a specific domain.

Request

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

# Request parameters
$requestUrl = $baseUrl + $endpoint
$requestHeaders = @{"Adm-Authorization" = YOUR-SECURITY-TOKEN}
$queryParams = @{
    "baseObject" = "DC=example,DC=com";
    "filter" = "LockedOutAccounts"
}

# Make request
Invoke-RestMethod -Method GET -Headers $requestHeaders -Uri $requestUrl -Body $queryParams
C#
using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        const string baseUrl = "https://host.example.com";
        const string endpoint = "/restApi/api/directoryObjects/search";

        // Request parameters
        const string baseObject = "DC=example,DC=com";
        const string criteria = "LockedOutAccounts";
        UriBuilder requestUrl = new()
        {
            Host = baseUrl + endpoint,
            Query = $"?baseObject={baseObject}" + $"&filter={criteria}"
        };

        // Initialize HTTP client
        using HttpClient client = new();
        client.DefaultRequestHeaders.Add("Adm-Authorization", YOUR-SECURITY-TOKEN);

        // Make request
        string response = await client.GetStringAsync(requestUrl.ToString());
        Console.WriteLine(response);
    }
}
cURL
curl  --header 'Adm-Authorization: YOUR-SECURITY-TOKEN' \
--get -X GET 'https://host.example.com/restApi/api/directoryObjects/search' \
--data-urlencode 'baseObject=DC=example,DC=com' \
--data-urlencode 'filter=LockedOutAccounts'
node.js
var https = require('https');

// Request parameters
var baseObject = "DC=example,DC=com";
var criteria = "LockedOutAccounts";
var requestPath = "/restApi/api/directoryObjects/search"
    + `?baseObject=${baseObject}`
    + `&filter=${criteria}`;

var options = {
    'method': 'GET',
    'hostname': 'host.example.com',
    'path': requestPath,
    'headers': {'Adm-Authorization': 'YOUR-SECURITY-TOKEN'}
};

// Make request
var req = https.request(options, res => {
    var data = [];

    res.on("data", chunk => {
        data.push(chunk);
    });

    res.on("end", () => {
        var body = Buffer.concat(data);
        console.log(body.toString());
    });

    res.on("error", error => {
        console.error(error);
    });
});
req.end();
Python
import requests
import json

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

# Request parameters
requestUrl = baseUrl + endpoint
requestHeaders = {"Adm-Authorization": YOUR-SECURITY-TOKEN}
queryParams = {
    "baseObject": "DC=example,DC=com",
    "filter": "LockedOutAccounts"
}   

# Make request
request = requests.get(requestUrl, headers=requestHeaders, params=queryParams)
response = json.loads(request.content)
print(response)

Response

HTTP Status code: 200 OK
Response body:

[
    {
        "accountStatus": {
            "isDisabled": false,
            "isLocked": true,
            "expirationDate": null
        },
        "passwordStatus": {
            "whenChanged": "2020-10-01T12:26:50.4085035Z",
            "expirationStatus": 1,
            "expirationDate": null
        },
        "guid": "2288a376-ef17-4319-8dea-edc291cf892a",
        "dn": "CN=John Sally,CN=Users,DC=example,DC=com",
        "displayName": "John Sally",
        "objectType": "user",
        "objectTypeCode": 2,
        "domainName": "example.com",
        "properties": {}
    },
    {
        "accountStatus": {
            "isDisabled": false,
            "isLocked": true,
            "expirationDate": null
        },
        "passwordStatus": {
            "whenChanged": "2020-10-01T12:26:50.1585044Z",
            "expirationStatus": 1,
            "expirationDate": null
        },
        "guid": "4bd4e1ed-be88-457c-ae6e-6aece10fc621",
        "dn": "CN=Anna Park,CN=Users,DC=example,DC=com",
        "displayName": "Anna Park",
        "objectType": "user",
        "objectTypeCode": 2,
        "domainName": "example.com",
        "properties": {}
    },
    {
        "accountStatus": {
            "isDisabled": true,
            "isLocked": true,
            "expirationDate": null
        },
        "passwordStatus": {
            "whenChanged": null,
            "expirationStatus": 1,
            "expirationDate": null
        },
        "guid": "7a53db58-87cd-4502-a8b1-d68d5a30bf44",
        "dn": "CN=Alfred Junior,CN=Users,DC=example,DC=com",
        "displayName": "Alfred Junior",
        "objectType": "user",
        "objectTypeCode": 2,
        "domainName": "example.com",
        "properties": {}
    }
]
 Example 5 – Retrieve all users enrolled for MFA in Adaxes

The following code sample retrieves all users who activated a mobile authenticator app in Adaxes.

Request

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

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

# Make request
Invoke-RestMethod -Method GET -Headers $requestHeaders -Uri $requestUrl -Body $queryParams
C#
using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        const string baseUrl = "https://host.example.com";
        const string endpoint = "/restApi/api/directoryObjects/search";

        // Request parameters
        const string criteria = "TotpEnrolledAccounts";
        UriBuilder requestUrl = new()
        {
            Host = baseUrl + endpoint,
            Query = $"?filter={criteria}"
        };

        // Initialize HTTP client
        using HttpClient client = new();
        client.DefaultRequestHeaders.Add("Adm-Authorization", YOUR-SECURITY-TOKEN);

        // Make request
        string response = await client.GetStringAsync(requestUrl.ToString());
        Console.WriteLine(response);
    }
}
cURL
curl  --header 'Adm-Authorization: YOUR-SECURITY-TOKEN' \
--get -X GET 'https://host.example.com/restApi/api/directoryObjects/search' \
--data-urlencode 'filter=TotpEnrolledAccounts'
node.js
var https = require('https');

// Request parameters
var criteria = "TotpEnrolledAccounts";
var requestPath = "/restApi/api/directoryObjects/search"
    + `?filter=${criteria}`;

var options = {
    'method': 'GET',
    'hostname': 'host.example.com',
    'path': requestPath,
    'headers': {'Adm-Authorization': 'YOUR-SECURITY-TOKEN'}
};

// Make request
var req = https.request(options, res => {
    var data = [];

    res.on("data", chunk => {
        data.push(chunk);
    });

    res.on("end", () => {
        var body = Buffer.concat(data);
        console.log(body.toString());
    });

    res.on("error", error => {
        console.error(error);
    });
});
req.end();
Python
import requests
import json

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

# Request parameters
requestUrl = baseUrl + endpoint
requestHeaders = {"Adm-Authorization": YOUR-SECURITY-TOKEN}
queryParams = {"filter": "TotpEnrolledAccounts"}   

# Make request
request = requests.get(requestUrl, headers=requestHeaders, params=queryParams)
response = json.loads(request.content)
print(response)

Response

HTTP Status code: 200 OK
Response body:

[
    {
        "accountStatus": {
            "isDisabled": false,
            "isLocked": false,
            "expirationDate": null
        },
        "passwordStatus": {
            "whenChanged": "2020-10-01T12:26:50.1585044Z",
            "expirationStatus": 1,
            "expirationDate": null
        },
        "guid": "4bd4e1ed-be88-457c-ae6e-6aece10fc621",
        "dn": "CN=Anna Park,CN=Users,DC=example,DC=com",
        "displayName": "Anna Park",
        "objectType": "user",
        "objectTypeCode": 2,
        "domainName": "example.com",
        "properties": {}
    },
    {
        "accountStatus": {
            "isDisabled": true,
            "isLocked": false,
            "expirationDate": null
        },
        "passwordStatus": {
            "whenChanged": null,
            "expirationStatus": 1,
            "expirationDate": null
        },
        "guid": "7a53db58-87cd-4502-a8b1-d68d5a30bf44",
        "dn": "CN=Alfred Junior,CN=Users,DC=example,DC=com",
        "displayName": "Alfred Junior",
        "objectType": "user",
        "objectTypeCode": 2,
        "domainName": "example.com",
        "properties": {}
    }
]
 Example 6 – Retrieve the emails and mobile numbers of users from a specific department

The following code sample retrieves all users from a specific department and their properties:

  • Email
  • Mobile Phone

Request

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

# Request parameters
$requestUrl = $baseUrl + $endpoint
$requestHeaders = @{"Adm-Authorization" = YOUR-SECURITY-TOKEN}
$queryParams = @{
    "filter" = "(department=Marketing)";
    "properties" = "mail,mobile"
}    

# Make request
Invoke-RestMethod -Method GET -Headers $requestHeaders -Uri $requestUrl -Body $queryParams
C#
using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        const string baseUrl = "https://host.example.com";
        const string endpoint = "/restApi/api/directoryObjects/search";

        // Request parameters            
        const string ldapFilter = "(department=Marketing)";
        const string propertiesToGet = "mail,mobile";
        UriBuilder requestUrl = new()
        {
            Host = baseUrl + endpoint,
            Query = $"?filter={ldapFilter}" + $"&properties={propertiesToGet}"
        };

        // Initialize HTTP client
        using HttpClient client = new();
        client.DefaultRequestHeaders.Add("Adm-Authorization", YOUR-SECURITY-TOKEN);

        // Make request
        string response = await client.GetStringAsync(requestUrl.ToString());
        Console.WriteLine(response);
    }
}
cURL
curl  --header 'Adm-Authorization: YOUR-SECURITY-TOKEN' \
--get -X GET 'https://host.example.com/restApi/api/directoryObjects/search' \
--data-urlencode 'filter=(department=Marketing)' \
--data-urlencode 'properties=mail,mobile'
node.js
var https = require('https');

// Request parameters
var ldapFilter = "(department=Marketing)";
var propertiesToGet = "mail,mobile";
var requestPath = "/restApi/api/directoryObjects/search"
    + `?filter=${ldapFilter}`
    + `&properties=${propertiesToGet}`;

var options = {
    'method': 'GET',
    'hostname': 'host.example.com',
    'path': requestPath,
    'headers': {'Adm-Authorization': 'YOUR-SECURITY-TOKEN'}
};

// Make request
var req = https.request(options, res => {
    var data = [];

    res.on("data", chunk => {
        data.push(chunk);
    });

    res.on("end", () => {
        var body = Buffer.concat(data);
        console.log(body.toString());
    });

    res.on("error", error => {
        console.error(error);
    });
});
req.end();
Python
import requests
import json

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

# Request parameters
requestUrl = baseUrl + endpoint
requestHeaders = {"Adm-Authorization": YOUR-SECURITY-TOKEN}
queryParams = {
    "filter": "(department=Marketing)",
    "properties": "mail,mobile"
}   

# Make request
request = requests.get(requestUrl, headers=requestHeaders, params=queryParams)
response = json.loads(request.content)
print(response)

Response

HTTP Status code: 200 OK
Response body:

[
    {
        "accountStatus": {
            "isDisabled": false,
            "isLocked": false,
            "expirationDate": null
        },
        "passwordStatus": {
            "whenChanged": "2020-10-01T12:26:50.1585044Z",
            "expirationStatus": 1,
            "expirationDate": null
        },
        "guid": "4bd4e1ed-be88-457c-ae6e-6aece10fc621",
        "dn": "CN=Anna Park,CN=Users,DC=example,DC=com",
        "displayName": "Anna Park",
        "objectType": "user",
        "objectTypeCode": 2,
        "domainName": "example.com",
        "properties": {
            "mail": [ "anna.park@example.com" ],
            "mobile": [ "908-432-9108" ]
        }
    },
    {
        "accountStatus": {
            "isDisabled": true,
            "isLocked": false,
            "expirationDate": null
        },
        "passwordStatus": {
            "whenChanged": null,
            "expirationStatus": 1,
            "expirationDate": null
        },
        "guid": "7a53db58-87cd-4502-a8b1-d68d5a30bf44",
        "dn": "CN=Alfred Junior,CN=Users,DC=example,DC=com",
        "displayName": "Alfred Junior",
        "objectType": "user",
        "objectTypeCode": 2,
        "domainName": "example.com",
        "properties": {
            "mail": [ "alfred.junior@example.com" ],
            "mobile": [ "405-657-0062" ]
        }
    }
]
 Example 7 – Retrieve all business units

The following code sample retrieves all business units.

Request

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

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

# Make request
Invoke-RestMethod -Method GET -Headers $requestHeaders -Uri $requestUrl -Body $queryParams
C#
using System;
using System.Web;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        const string baseUrl = "https://host.example.com";
        const string endpoint = "/restApi/api/directoryObjects/search";

        // Request parameters
        string baseObject = HttpUtility.UrlEncode("wkobj:BusinessUnitsContainer");
        UriBuilder requestUrl = new()
        {
            Host = baseUrl + endpoint,
            Query = $"?baseObject={baseObject}" 
        };

        // Initialize HTTP client
        using HttpClient client = new();
        client.DefaultRequestHeaders.Add("Adm-Authorization", YOUR-SECURITY-TOKEN);

        // Make request
        string response = await client.GetStringAsync(requestUrl.ToString());
        Console.WriteLine(response);
    }
}
cURL
curl  --header 'Adm-Authorization: YOUR-SECURITY-TOKEN' \
--get -X GET 'https://host.example.com/restApi/api/directoryObjects/search' \
--data-urlencode 'baseObject=wkobj:BusinessUnitsContainer' \
node.js
var https = require('https');

// Request parameters
var baseObject = encodeURIComponent("wkobj:BusinessUnitsContainer");
var requestPath = "/restApi/api/directoryObjects/search"
    + `?baseObject=${baseObject}`

var options = {
    'method': 'GET',
    'hostname': 'host.example.com',
    'path': requestPath,
    'headers': {'Adm-Authorization': 'YOUR-SECURITY-TOKEN'}
};

// Make request
var req = https.request(options, res => {
    var data = [];

    res.on("data", chunk => {
        data.push(chunk);
    });

    res.on("end", () => {
        var body = Buffer.concat(data);
        console.log(body.toString());
    });

    res.on("error", error => {
        console.error(error);
    });
});
req.end();
Python
import requests
import json

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

# Request parameters
requestUrl = baseUrl + endpoint
requestHeaders = {"Adm-Authorization": YOUR-SECURITY-TOKEN}
queryParams = {"baseObject": "wkobj:BusinessUnitsContainer"}   

# Make request
request = requests.get(requestUrl, headers=requestHeaders, params=queryParams)
response = json.loads(request.content)
print(response)

Response

HTTP Status code: 200 OK
Response body:

[
    {
        "rootContainerDN": "CN=Business Units,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes",
        "guid": "742a1aab-99ee-48c7-8a3a-97d8d26988e0",
        "dn": "CN=My Unit,CN=Business Units,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes",
        "displayName": "My Unit",
        "objectType": "adm-BusinessUnit",
        "objectTypeCode": 100,
        "domainName": "",
        "properties": {}
    },
    {
        "rootContainerDN": "CN=Business Units,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes",
        "guid": "4239a090-2915-4b05-b808-b5610595fa8b",
        "dn": "CN=Deprovisioned Users,CN=Business Units,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes",
        "displayName": "Deprovisioned Users",
        "objectType": "adm-BusinessUnit",
        "objectTypeCode": 100,
        "domainName": "",
        "properties": {}
    }
]

See also