Skip to main content

Source(nameOrId)

Returns a handle for one source. Pass the name or the id.

const orders = sdk.asAdmin().Insights().Source('Orders')

The SDK resolves names via GET /api/v2/source and caches the map for five minutes (refresh is skipped if the cache is younger than 10 seconds). Unknown names throw insights/source-not-found.

get(schema = false)​

GET /api/v2/source/{sourceId}[?schema=true]

Returns the source with its config, fieldTypes, rawDocCount and totalDocCount. With schema: true the result also includes schema: { validation, render, translations }, a form definition for the source's fields.

const { result } = await orders.get(true)
console.log(result.fieldTypes)

aggregate(params)​

POST /api/v2/source/{sourceId}/aggregate. Guide: Query data.

ParameterTypeDescription
sizenumberRows per page
fromnumberOffset (not with pageKey)
fieldsstring[]Fields to return
filterarrayElasticsearch query clauses. Array required
sortarrayElasticsearch sort clauses. Array required
pageKeyarray or objectnextPageKey of the previous response (array for document lists, object in composite mode)
aggsarrayGrouping and metric stages. See the Query reference
aggMode'aggregation' | 'composite'How aggs are evaluated. Required when aggs is set
includeFieldTypesbooleanInclude fieldTypes in the response
rawbooleanRead the raw (untransformed) documents

Response: { rows, aggs, aggMode, nextPageKey, filteredDocCount, totalDocCount: { value, relation }, fieldTypes }.

Errors: sdk/aggregate-filter-must-be-array, sdk/aggregate-sort-must-be-array, 404 get-table-data/unknown-source.

push(docs)​

POST /api/v2/source/{sourceId}/push. Queues one document or an array. Service tokens and push sources only.

Response { ok: true, queued: n }.

Errors: push/invalid-source-type, push/source-not-ready, push/empty-body.