This method is used to create a new LDAP object in the directory. The required attributes in the attrs array depend on the type of object you are creating (e.g., user, group, etc.). Ensure you provide all necessary attributes for the specific object class.

This method requires two parameters:

  1. dn (String): The Distinguished Name (DN) of the object you are creating.
  2. attrs (Array): An array of LDAP attributes and their corresponding values that define the object.

Example: Creating a User

When creating a user object, a typical attrs array might include:

  • objectclass: Defines the classes of the user object (e.g., person, inetOrgPerson, webadmAccount).
  • uid: The unique identifier for the user.
  • userpassword: The password for the user.
  • sn: The user's surname or last name.

Example attrs array for a user:

{
  "objectclass": ["inetOrgPerson", "user", "webadmAccount"],
  "samacountname": "jane.doe",
  "userprincipalname" : "jane.doe@rcdevsdocs.com",
  "userpassword": "password123",
  "sn": "Doe"
}

Return Values

  • true: Indicates the object was successfully created.
  • false: Indicates an error occurred during creation.

This method is flexible and can be used to create any LDAP object. The attributes provided in the attrs array should be tailored to the object type (e.g., user, group, etc.). Always refer to your LDAP schema for required attributes for the object class you are creating.


import requests
import json

# Define the method and parameters
method = 'Create_LDAP_Object'
params = {
    'dn': 'cn=jane doe,cn=users,dc=rcdevsdocs,dc=com',
    'attrs': {
        'objectclass': ['user', 'person', 'webadmaccount'],
        'samaccountname': ['jane.doe'],
        'userprincipalname': ['jane.doe@rcdevsdocs.com'],
        'userpassword': ['myPassword'],
        'sn': ['Jane']
    }
}

# 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 = 'Create_LDAP_Object';
$params = array(
    'dn' => 'cn=jane doe,cn=users,dc=rcdevsdocs,dc=com',
    'attrs' => array(
        'objectclass' => array('user', 'person', 'inetorgperson'),
        'samaccountname' => array('jane.doe'),
        'userprincipalname' => array('jane.doe@rcdevsdocs.com'),
        'userpassword' => array('myPassword'),
        'sn' => array('Jane')
    )
);

$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 = 'Create_LDAP_Object'
$params = @{
    dn = 'cn=jane doe,cn=users,dc=rcdevsdocs,dc=com'
    attrs = @{
        objectclass = @('user', 'person', 'inetorgperson')
        samaccountname = @('jane.doe')
        userprincipalname = @('jane.doe@rcdevsdocs.com')
        userpassword = @('myPassword')
        sn = @('Jane')
    }
}

$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