List, filter and search
Two calls find entities. Use list for tables and exports, search for typeahead and full-text lookups.
Entities.list | Entities.search | |
|---|---|---|
| Entity types | several at once (entityTypes) | exactly one (entityType) |
Free-text quickFilter | no | yes (n-gram search) |
| Paging | optional (pagination), or everything | none |
| Returns OU ancestors | no | yes, for OU matches |
List everything of a type
const customers = sdk.asAdmin().Customers()
const { result } = await customers.Entities.list({
entityTypes: ['ou'],
fields: ['data.name', 'data.city', 'data.legalForm'],
hideInactive: true
})
Without pagination the API returns all matching entities as an array, reading the index in pages of 10,000 internally. Each row has entityType, id, humanId, the name fields and your fields, plus a score.
Filter
const { result } = await customers.Entities.list({
entityTypes: ['ou'],
fields: ['data.name', 'data.city'],
filterModel: {
logicOperator: 'and',
items: [
{ field: 'data.city', operator: 'equals', value: 'Hamburg' },
{ field: 'data.name', operator: 'contains', value: 'Nordlicht' }
]
}
})
logicOperator is and or or. Each item has field, operator and value.
| Field type | Operators |
|---|---|
| string | contains, doesNotContain, startsWith, endsWith, equals, isEmpty, isNotEmpty |
| boolean | equals, isEmpty, isNotEmpty |
relations (__GROUPS__, __MEMBERS__, __EMPLOYEES__, __EMPLOYMENTS__, __ROLES__) | includes (default), excludes |
Handy field names:
| Use | Field |
|---|---|
| Email / phone of any entity | contacts.email, contacts.phone, contacts.mobile, contacts.fax |
| humanId | humanId |
| Bank IBAN | data.bankHistory (matches the IBAN) |
Everyone in a group
const { result: groups } = await customers.Entities.search({
entityType: 'group',
filterModel: { logicOperator: 'and', items: [{ field: 'data.name', operator: 'equals', value: 'Key accounts' }] },
idsOnly: true
})
const { result: members } = await customers.Entities.list({
entityTypes: ['ou', 'person'],
filterModel: {
logicOperator: 'and',
items: [{ field: '__GROUPS__', operator: 'includes', value: groups[0].humanId }]
}
})
Sort
The sort format depends on whether you page.
// Without pagination: Elasticsearch sort clauses. Text fields need the .keyword suffix.
await customers.Entities.list({
entityTypes: ['person'],
fields: ['data.lastName'],
sort: [{ 'data.lastName.keyword': 'asc' }]
})
// With pagination: { field, sort, fieldType? }. The API adds .keyword for text fields.
await customers.Entities.list({
entityTypes: ['person'],
pagination: { page: 0, pageSize: 100 },
sort: [{ field: 'data.lastName', sort: 'asc' }]
})
Page through large result sets
Pass pagination and the response changes to { rows, totalCount }:
const { result } = await customers.Entities.list({
entityTypes: ['person'],
pagination: { page: 0, pageSize: 100 },
sort: [{ field: 'data.lastName', sort: 'asc' }]
})
console.log(result.totalCount, result.rows.length)
The window is limited to 10,000 results. Beyond that the API answers entity/pagination-window-exceeded. Narrow the filter instead.
pagination is passed through by the SDK but not yet described in its JSDoc.
Full-text search
const { result } = await customers.Entities.search({
entityType: 'ou',
quickFilter: 'nordl',
fields: ['data.name', 'data.city'],
hideInactive: true
})
quickFilter matches name fields with n-grams, so partial words work. searchSubEntities: true also searches sub-entities. idsOnly: true returns only identifiers, useful for lookups.
Results are ordered by score. For OU matches, the ancestors of each match are appended (without a score) so you can render the tree.
Exports
import { writeFile } from 'fs/promises'
const { result } = await customers.Entities.list({
entityTypes: ['person'],
fields: ['data.firstName', 'data.lastName', 'data.contacts']
})
const emailOf = person => person.data?.contacts?.find(c => c.contactType === 'email')?.value?.email ?? ''
const lines = result.map(p => [p.humanId, p.data.firstName, p.data.lastName, emailOf(p)].join(','))
await writeFile('people.csv', ['humanId,firstName,lastName,email', ...lines].join('\n'))