# ldap-query()

```
OXN-node-set ldap-query(string url, string rdn, string rdnPassword, string base_dn, string search, string attributes)
```

The `ldap-query()` function connects to an LDAP server with the given `url`, `rdn` and `rdnPassword`. It then performs a query by the given `search`. An [OXN](/flat/reference/templating/oxn.md) JSON array is returned with objects containing `dn` and additional attributes given by `attributes` of all the entities that were found. If no entities match the query, an empty node-set is returned.

## Parameters

* `url` The ldap URL (string)
* `rdn` The (relative) distinguished name of the connecting user (string)
* `rdnPassword` The password of the connecting user (string)
* `base_dn` The base distinguished name for the directory, used for the search (string)
* `search` The filter for searching entities (string)
* `attributes` A comma-separated list of attributes to return (string)

## Example

In the following example, FLAT connects to the LDAP server with the DN given in the `rdn` and `rdnPassword` POST parameters. The given filter is used to search for an entry of a person which is a member of a group `Users` and sAMAccountName containing `doe`. In addition to the (default) `dn`, the `sAMAccountName`, `displayName` and `mail` from the found entries are included in the results.

```markup
<flow>
  <eval out="$search">concat("(&amp;(objectClass=person)(memberOf=CN=Users,ou=People,dc=example,dc=com)(sAMAccountName=*doe*))")</eval>
  <eval out="$attributes">"sAMAccountName,displayName,mail"</eval>
  <eval out="$ldap_url">"ldap://ad.example.com"</eval>

  <eval out="$ldap">ldap-lookup($ldap_url, $request/post/rdn, $request/post/rdnPassword, "dc=example,dc=com", $search, $attributes)</eval>
  <error if="not($ldap)">
  {
    "status": 403,
    "message": "ldap-lookup() failed"
  }
  </error>
</flow>
```

The result is

```javascript
[
  {
    "dn": "cn=John Doe,ou=People,dc=example,dc=com",
    "sAMAccountName": "john.doe",
    "displayName": "John Doe",
    "mail": "john.doe@example.com"
  },
  {
    "dn": "cn=Joseph Adoell,ou=People,dc=example,dc=com",
    "sAMAccountName": "joseph.adoell",
    "displayName": "Joseph Adoell",
    "mail": "joseph.adoell@example.com"
  }
]
```


---

# 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://sevenval.gitbook.io/flat/reference/functions/ldap-query.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.
