# Ldap

## Add an attribute (e.g. "member of") to the entry identified by "filterDN"

**Syntax**

```javascript
var num = utils.addAttribute(host, port, filterDN, ldapUsername, ldapPassword, attributeNameToAdd, attributeValueToAdd);
```

**Details**

| Argument | Description                                              |
| -------- | -------------------------------------------------------- |
| host     | LDAP host                                                |
| port     | LDAP port (optional: if not specified, 389 will be used) |

```
 filterDN - base DN to apply as a filter
```

| Argument            | Description                                                        |
| ------------------- | ------------------------------------------------------------------ |
| ldapUsername        | username to use to authenticate to the LDAP server                 |
| ldapPassword        | password to use to authenticate to the LDAP server                 |
| attributeNameToAdd  | attribute name to add to every entry matching the search criteria  |
| attributeValueToAdd | attribute value to add to every entry matching the search criteria |

```
Returns the number of entries found and updated
```

## Remove an attribute (e.g. "memberOf") from the entry identified by "filterDN"

**Syntax**

```javascript
var num = utils.removeAttribute(host, port, filterDN, ldapUsername, ldapPassword, attributeNameToRemove, attributeValueToRemove);
```

**Details**

| Argument | Description                                              |
| -------- | -------------------------------------------------------- |
| host     | LDAP host                                                |
| port     | LDAP port (optional: if not specified, 389 will be used) |

```
 filterDN - base DN to apply as a filter
```

| Argument               | Description                                                             |
| ---------------------- | ----------------------------------------------------------------------- |
| ldapUsername           | username to use to authenticate to the LDAP server                      |
| ldapPassword           | password to use to authenticate to the LDAP server                      |
| attributeNameToRemove  | attribute name to remove from every entry matching the search criteria  |
| attributeValueToRemove | attribute value to remove from every entry matching the search criteria |

```
Returns number of entries found and updated
```

## Get a list of records read from the LDAP server

where each record is expressed as a Javascript Object

**Syntax**

```javascript
var listOfObjects = utils.getEntriesList(host, port, baseDN, ldapUsername, ldapPassword, searchAttributes,attributesListToRead);
```

**Details**

| Argument | Description                                              |
| -------- | -------------------------------------------------------- |
| host     | LDAP host                                                |
| port     | LDAP port (optional: if not specified, 389 will be used) |

```
 baseDN - base DN to apply as a filter
```

| Argument             | Decription                                                                                                                                               |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ldapUsername         | username to use to authenticate to the LDAP server                                                                                                       |
| ldapPassword         | password to use to authenticate to the LDAP server                                                                                                       |
| searchAttributes     | attributes to apply as a filter                                                                                                                          |
| attributesListToRead | list of attribute names to take into account when reading records from the LDAP server: these will be the only ones to use when creating the JSON result |

```
Returns a list of records read from the LDAP server, where each record is expressed as a Javascript object.
```

## Get a list of Strings, related to multiple attribute values

starting from a specified attribute name of a specific entry read from the LDAP server

**Syntax**

```javascript
var listOfStrings = utils.getMultipleValuesList(host, port, baseDN, ldapUsername, ldapPassword, searchAttributes, attributeName);
```

**Details**

| Argument | Description                                              |
| -------- | -------------------------------------------------------- |
| host     | LDAP host                                                |
| port     | LDAP port (optional: if not specified, 389 will be used) |

```
 baseDN - base DN to apply as a filter
```

| Argument         | Description                                                                               |
| ---------------- | ----------------------------------------------------------------------------------------- |
| ldapUsername     | username to use to authenticate to the LDAP server                                        |
| ldapPassword     | password to use to authenticate to the LDAP server                                        |
| searchAttributes | attributes to apply as a filter, in order to identity a single entry into the LDAP server |
| attributeName    | attribute name to read: each matching found will generate a row in the results list       |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://4wsplatform.gitbook.io/api/server-side-javascript-api/ldap.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
