Skip to main content

List, filter and search

Two calls find entities. Use list for tables and exports, search for typeahead and full-text lookups.

Entities.listEntities.search
Entity typesseveral at once (entityTypes)exactly one (entityType)
Free-text quickFilternoyes (n-gram search)
Pagingoptional (pagination), or everythingnone
Returns OU ancestorsnoyes, 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 typeOperators
stringcontains, doesNotContain, startsWith, endsWith, equals, isEmpty, isNotEmpty
booleanequals, isEmpty, isNotEmpty
relations (__GROUPS__, __MEMBERS__, __EMPLOYEES__, __EMPLOYMENTS__, __ROLES__)includes (default), excludes

Handy field names:

UseField
Email / phone of any entitycontacts.email, contacts.phone, contacts.mobile, contacts.fax
humanIdhumanId
Bank IBANdata.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.

note

pagination is passed through by the SDK but not yet described in its JSDoc.

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'))