This method allows you to search for an LDAP object, functioning similarly to an LDAP search operation.

The mandatory setting is the basedn, which corresponds to the DN (Distinguished Name) treebase from where the search will begin in the LDAP directory.

By setting the filter, you can apply an LDAP filter to refine your search. The default filter is (objectclass=*), which retrieves all objects.

By setting the scope, you can define the search level:

  • base searches only the object specified by basedn,
  • one searches one level below the basedn,
  • sub searches the entire subtree beneath the basedn.

The attrs parameter allows you to specify an array of LDAP attributes to return in the results. If not specified, all attributes of the matched objects are returned.

The method returns an array of objects, with each object containing an array of attributes and their corresponding values.


import requests
import json

# Define the method and parameters
method = 'Search_LDAP_Object'
params = {
    'basedn': 'cn=users,dc=rcdevsdocs,dc=com',
    'scope': 'one',
    'attrs': ['objectclass', 'samaccountname'],
    'filter': '(objectclass=*)'
}

# Create the request payload
request_payload = {
    'jsonrpc': "2.0",
    'method': method,
    'params': params,
    'id': 0
}

# Convert payload to JSON
json_payload = json.dumps(request_payload)

# Define the URL and credentials
url = "https://webadm1.rcdevsdocs.com/manag/"
auth = ("RCDEVSDOCS\\administrator", "password")

# Define the headers
headers = {
    "Content-Type": "application/json",
    "Connection": "close"
}

# Make the POST request
response = requests.post(url, data=json_payload, headers=headers, auth=auth, verify=False)

# Print the HTTP response code and response content
print(f"HTTP response code: {response.status_code}")
print(response.json())
    

<?php
#!/bin/php
$method = 'Search_LDAP_Object';
$params = array(
    'basedn' => 'cn=users,dc=rcdevsdocs,dc=com',
    'scope' => 'one',
    'attrs' => array('objectclass', 'samaccountname'),
    'filter' => '(objectclass=*)'
);

$request = array(
    'jsonrpc' => "2.0",
    'method' => $method,
    'params' => $params,
    'id' => 0
);
$json = json_encode($request);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://webadm1.rcdevsdocs.com/manag/");
curl_setopt($ch, CURLOPT_USERPWD, "RCDEVSDOCS\\administrator:password");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("connection: close"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$out = curl_exec($ch);
curl_close($ch);

print_r(json_decode($out));
?>
    

$method = 'Search_LDAP_Object'
$params = @{
    basedn = 'cn=users,dc=rcdevsdocs,dc=com'
    scope = 'one'
    attrs = @('objectclass', 'samaccountname')
    filter = '(objectclass=*)'
}

$request = @{
    jsonrpc = "2.0"
    method = $method
    params = $params
    id = 0
}

$json = $request | ConvertTo-Json

$uri = "https://webadm1.rcdevsdocs.com/manag/"
$headers = @{
    "Content-Type" = "application/json"
    "Connection" = "close"
}

$creds = Get-Credential -UserName "RCDEVSDOCS\administrator" -Message "Enter password"
$response = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $json -Credential $creds -SkipCertificateCheck

Write-Output "HTTP response code: $($response.StatusCode)"
$response | ConvertTo-Json