Skip to main content

Query API

Usageโ€‹

import { epilot } from '@epilot/sdk'

epilot.authorize(() => '<token>')
const { data } = await epilot.query.createOrUpdateView(...)

Tree-shakeable importโ€‹

import { getClient, authorize } from '@epilot/sdk/query'

const queryClient = getClient()
authorize(queryClient, () => '<token>')
const { data } = await queryClient.createOrUpdateView(...)

Operationsโ€‹

Datalake V2

Datasets

Query

V1

CredentialsV2

V2

Schemas

createOrUpdateViewโ€‹

Create or update a materialized SQL view in the epilot data lake.

POST /datalake/views

const { data } = await client.createOrUpdateView(
null,
{
view_name: 'some_view',
source_dataset: 'current_entities',
config: {
schema: 'some_schema',
include_purpose_view: true,
include_label_view: true,
include_relation_view: true,
relationship_attribute: ['some_relationship_attribute']
}
},
)
Response
{
"view_name": "some_view",
"source_dataset": "current_entities",
"attributes": [
{
"name": "some_attribute",
"type": "string",
"description": "some description"
}
]
}

getAllViewsโ€‹

Retrieve all materialized data lake views configured for the organization.

GET /datalake/views

const { data } = await client.getAllViews()
Response
{
"views": [
{
"view_name": "some_view",
"source_dataset": "current_entities",
"view_slug": "some_view",
"attributes": [
{
"name": "some_attribute",
"type": "string",
"description": "some description"
}
]
},
{
"view_name": "another_view",
"source_dataset": "taxonomies",
"view_slug": "another_view",
"attributes": [
{
"name": "taxonomy_attribute",
"type": "string",
"description": "taxonomy attribute description"
}
]
}
]
}

getViewโ€‹

Retrieve the definition and attributes of a specific data lake view by its slug.

GET /datalake/views/{view_slug}

const { data } = await client.getView({
view_slug: 'example',
})
Response
{
"view_name": "some_view",
"source_dataset": "current_entities",
"attributes": [
{
"name": "some_attribute",
"type": "string",
"description": "some description"
}
]
}

createOrUpdateRelationshipโ€‹

Define or update a relationship between two tables in the data lake.

POST /datalake/relationships

const { data } = await client.createOrUpdateRelationship(
null,
{
relationship_name: 'some_relationship',
from_table: 'some_table',
to_table: 'some_table',
from_column: 'some_column',
to_column: 'some_column',
type: 'one_to_many'
},
)
Response
{
"relationship_name": "some_relationship",
"from_table": "some_table",
"to_table": "some_table",
"from_column": "some_column",
"to_column": "some_column",
"type": "one_to_many"
}

getAllRelationshipsโ€‹

Retrieve all table relationships configured for the organization's data lake.

GET /datalake/relationships

const { data } = await client.getAllRelationships()
Response
{
"relationships": [
{
"relationship_name": "some_relationship",
"from_table": "some_table",
"to_table": "some_table",
"from_column": "some_column",
"to_column": "some_column",
"type": "one_to_many"
},
{
"relationship_name": "another_relationship",
"from_table": "table_a",
"to_table": "table_b",
"from_column": "column_a",
"to_column": "column_b",
"type": "many_to_many"
}
]
}

listAvailableDatasetsV2โ€‹

Lists all available datasets grouped by domain

GET /v2/query/datasets

const { data } = await client.listAvailableDatasetsV2()
Response
{
"results": [
{
"domain": "entities",
"dataset": "entity_operations",
"endpoint": "/v2/query/domain/entities:execute"
},
{
"domain": "workflows",
"dataset": "workflow_execution_time_series",
"endpoint": "/v2/query/domain/workflows:execute"
}
]
}

executeEntitiesQueryโ€‹

Execute queries against entities datasets.

POST /v2/query/domain/entities:execute

const { data } = await client.executeEntitiesQuery(
{
cache_expiration: 'example',
no_cache: true,
},
{
query: {}
},
)
Response
{
"status": "FINISHED",
"timestamp": "1715621496068",
"results": [
{}
]
}

executeWorkflowsQueryโ€‹

Query Workflow Analytics Datasets.

POST /v2/query/domain/workflows:execute

const { data } = await client.executeWorkflowsQuery(
{
mock: true,
cache_expiration: 'example',
no_cache: true,
},
{
dataset: 'total_count_of_workflow_executions',
workflow_definition_ids: ['string'],
entity_schemas: ['string'],
states: ['string'],
group_time_by: 'M',
relative_time_range: 'string',
time_range_from: 'string',
time_range_to: 'string',
duration_threshold: 0
},
)
Response
{
"data": [0, 1],
"labels": ["label1", "label2"],
"timestamp": "1715621496068"
}

executeAutomationQueryโ€‹

Query Automation Analytics Datasets.

POST /v2/query/domain/automations:execute

const { data } = await client.executeAutomationQuery(
{
from: 1,
size: 1,
},
{
dataset: 'automation_executions_overview',
flow_ids: ['string'],
execution_states: ['success', 'failed', 'scheduled'],
relative_time_range: 'all_time',
time_range_from: 'string',
time_range_to: 'string'
},
)
Response
{
"hits": 100,
"results": [
{
"flow_id": "1234567890",
"flow_name": "flow_name",
"execution_id": "execution_id",
"execution_status": "execution_status",
"entity_schema": "opportunity",
"entity_id": "entity_id",
"created_at": "execution_created_at",
"updated_at": "execution_updated_at",
"error": {
"message": "error_message",
"error_code": "error_code"
},
"trigger_event": {
"type": "EntityOperation",
"trigger_type": "createEntity"
}
}
]
}

listWorkflowPhasesByDefinitionIdโ€‹

Retrieves the workflow phases associated with a given workflow definition ID.

GET /v2/query/domain/workflows/definitions/{workflowDefinitionId}/phases

const { data } = await client.listWorkflowPhasesByDefinitionId({
workflowDefinitionId: 'example',
})
Response
[
{
"id": "y0UdVCOI",
"name": "Initial Phase"
}
]

listWorkflowDefinitionsโ€‹

Lists available worflow definitions with their ids, names and start times

GET /v2/query/domain/workflows/definitions

const { data } = await client.listWorkflowDefinitions({
mock: true,
})
Response
{
"results": [
{
"id": "y0UdVCOI",
"name": "PV Kauf",
"max_date": "2023-05-31T00:00:00.000Z",
"min_date": "2023-01-00T00:00:00.000Z"
}
]
}

listPhaseNamesโ€‹

Lists phase names of an org.

GET /v2/query/domain/workflows/phases

const { data } = await client.listPhaseNames({
org_id: 'example',
})
Response
{
"results": [
{
"id": "y0UdVCOI",
"name": "PV Kauf",
"max_date": "2023-05-31T00:00:00.000Z",
"min_date": "2023-01-00T00:00:00.000Z"
}
]
}

listDatasetsโ€‹

Get list of available datasets

GET /v1/query/datasets

const { data } = await client.listDatasets()
Response
{
"results": [
{
"dataset": "entity_operations"
},
{
"dataset": "entities_timemachine"
}
]
}

executeQueryโ€‹

Execute queries against datasets.

POST /v1/query:execute

const { data } = await client.executeQuery(
{
cache_expiration: 'example',
no_cache: true,
},
{
query: {}
},
)
Response
{
"status": "FINISHED",
"timestamp": "1715621496068",
"results": [
{}
]
}

generateCredentialsV2โ€‹

Generate credentials for the epilot datalake for connecting other BI tools with ClickHouse

POST /v2/query/credentials:generate

const { data } = await client.generateCredentialsV2()
Response
{
"username": "datalakeuser_sfsdfs_66",
"password": "***",
"endpoints": {
"host": "qjjcxsy87t.eu-central-1.aws.clickhouse.cloud",
"port": 8443
},
"database": "datawarehouse"
}

listCredentialsV2โ€‹

List all the credentialof Clickhouse for the organization here

GET /v2/query/credentials:list

const { data } = await client.listCredentialsV2()
Response
{
"users": [
{
"user_id": "string"
}
]
}

revokeCredentialsV2โ€‹

Revoke credentials for the epilot datalake for connecting other BI tools with Clickhouse

POST /v2/query/credentials:revoke

const { data } = await client.revokeCredentialsV2({
user_id: 'example',
})
Response
{
"success": true
}

executeQueryV2โ€‹

Execute queries against datasets.

POST /v2/query:execute

const { data } = await client.executeQueryV2(
null,
{},
)
Response
{
"status": "FINISHED",
"timestamp": "1715621496068",
"results": [
{}
]
}

getSemanticModelโ€‹

Get the semantic model for agent/tool consumption.

GET /v2/query/semantic-model

const { data } = await client.getSemanticModel()
Response
{
"entities": [
{
"name": "current_contacts",
"displayName": "Contacts",
"schema": "entity"
}
],
"relationships": [
{
"from": "current_contacts",
"to": "opportunity_account_contact_relation",
"relationship": "hasMany",
"displayName": "Contact has many Opportunities"
}
],
"capabilities": {
"aggregations": ["count", "count_distinct", "sum", "average", "min", "max", "median"],
"calculationTypes": [
{
"type": "string",
"description": "string",
"parameters": {}
}
],
"granularities": ["day", "week", "month", "quarter", "year"],
"filterOperators": [
{
"operator": "string",
"description": "string"
}
]
}
}

autocompleteโ€‹

Generic autocomplete endpoint for querying distinct values across datasets. Use the dataset parameter to specify which data category to query.

GET /v2/query/autocomplete

const { data } = await client.autocomplete({
dataset: 'example',
input: 'example',
attribute: 'example',
size: 1,
})
Response
{
"results": ["value"]
}

workflowsAutocompleteโ€‹

Autocomplete Workflows data

GET /v2/query/workflows:autocomplete

const { data } = await client.workflowsAutocomplete({
input: 'example',
attribute: 'example',
size: 1,
})
Response
{
"results": ["value"]
}

Schemasโ€‹

ErrorResponseโ€‹

Standard error response body

type ErrorResponse = {
status?: number
error?: string
message?: string
}

ViewRequestโ€‹

type ViewRequest = {
view_name?: string
source_dataset: "current_entities"
config: {
schema: string
include_purpose_view?: boolean
include_label_view?: boolean
include_relation_view?: boolean
relationship_attribute?: string[]
}
} | {
view_name?: string
source_dataset: "taxonomies"
} | {
view_name?: string
source_dataset: "workflow_executions"
}

CurrentEntitiesViewRequestโ€‹

type CurrentEntitiesViewRequest = {
view_name?: string
source_dataset: "current_entities"
config: {
schema: string
include_purpose_view?: boolean
include_label_view?: boolean
include_relation_view?: boolean
relationship_attribute?: string[]
}
}

TaxonomiesViewRequestโ€‹

type TaxonomiesViewRequest = {
view_name?: string
source_dataset: "taxonomies"
}

WorkflowExecutionsViewRequestโ€‹

type WorkflowExecutionsViewRequest = {
view_name?: string
source_dataset: "workflow_executions"
}

ViewResponseโ€‹

type ViewResponse = {
view_name: string
source_dataset: "current_entities" | "taxonomies" | "workflow_executions"
attributes: Array<{
name: string
type: string
description?: string
}>
}

ViewsListResponseโ€‹

type ViewsListResponse = {
views?: Array<{
view_name: string
source_dataset: "current_entities" | "taxonomies" | "workflow_executions"
view_slug?: string
attributes: Array<{
name: { ... }
type: { ... }
description?: { ... }
}>
}>
}

RelationshipRequestโ€‹

type RelationshipRequest = {
relationship_name: string
from_table: string
to_table: string
from_column: string
to_column: string
type: "one_to_many" | "many_to_many" | "many_to_one" | "one_to_one"
}

RelationshipResponseโ€‹

type RelationshipResponse = {
relationship_name?: string
from_table?: string
to_table?: string
from_column?: string
to_column?: string
type?: "one_to_many" | "many_to_many" | "many_to_one" | "one_to_one"
}

RelationshipsListResponseโ€‹

type RelationshipsListResponse = {
relationships?: Array<{
relationship_name?: string
from_table?: string
to_table?: string
from_column?: string
to_column?: string
type?: "one_to_many" | "many_to_many" | "many_to_one" | "one_to_one"
}>
}

NoCacheโ€‹

type NoCache = boolean

CacheExpirationโ€‹

Cache Expiration timestamp

type CacheExpiration = string // timestamp

UserIdโ€‹

Execution Id for the query

type UserId = string

DatasetDomainโ€‹

type DatasetDomain = "entities" | "workflows"

Datasetโ€‹

type Dataset = {
dataset?: string
domain?: "entities" | "workflows"
endpoint?: string
}

DatalakeQueryOptionsโ€‹

type DatalakeQueryOptions = {
dataset?: string
measure?: string
dimensions?: Record<string, unknown>[]
filters?: Record<string, unknown>[]
exclude_deleted?: boolean
}

DatalakeQueryโ€‹

type DatalakeQuery = {
dataset?: string
measure?: string
dimensions?: Record<string, unknown>[]
filters?: Record<string, unknown>[]
exclude_deleted?: boolean
}

AutomationQueryOptionsโ€‹

type AutomationQueryOptions = {
dataset: "automation_executions_overview" | "list_automation_definitions"
}

DatasetOptions.AutomationExecutionsOverviewโ€‹

type DatasetOptions.AutomationExecutionsOverview = {
dataset: "automation_executions_overview" | "list_automation_definitions"
flow_ids?: string[]
execution_states?: string[]
relative_time_range?: "all_time" | "this_week" | "last_week" | "last_7_days" | "this_month" | "last_month" | "last_30_days" | "last_3_months" | "last_6_months" | "this_year" | "last_year"
time_range_from?: string
time_range_to?: string
}

DatasetOptions.ListAutomationDefinitionsโ€‹

type DatasetOptions.ListAutomationDefinitions = {
dataset: "automation_executions_overview" | "list_automation_definitions"
search?: string
}

WorkflowsQueryOptionsโ€‹

Settings for the data of the chart that is being queried.

type WorkflowsQueryOptions = {
dataset?: "total_count_of_workflow_executions" | "workflow_execution_time_series" | "cumulative_sum_of_workflows" | "cancellation_reasons" | "phases_count" | "phases_duration" | "tasks_duration" | "task_duration" | "workflow_tasks_overview"
workflow_definition_ids?: string[]
entity_schemas?: string[]
states?: string[]
group_time_by?: string
relative_time_range?: string
time_range_from?: string
time_range_to?: string
duration_threshold?: number
}

DatasetOptions.TotalCountOfWorkflowExecutionsโ€‹

See the total of workflow executions in a pie chart.

type DatasetOptions.TotalCountOfWorkflowExecutions = {
workflow_definition_ids?: string[]
entity_schema?: string
relative_time_range?: string
time_range_from?: string
time_range_to?: string
}

DatasetOptions.WorkflowExecutionTimeSeriesโ€‹

type DatasetOptions.WorkflowExecutionTimeSeries = {
workflow_definition_ids?: string[]
entity_schema?: string
relative_time_range?: string
time_range_from?: string
time_range_to?: string
workflow_states?: string[]
group_time_by?: string
}

DatasetOptions.CumulativeSumOfWorkflowsโ€‹

type DatasetOptions.CumulativeSumOfWorkflows = {
workflow_definition_ids?: string[]
entity_schema?: string
relative_time_range?: string
time_range_from?: string
time_range_to?: string
workflow_states?: string[]
group_time_by?: string
}

DatasetOptions.CancellationReasonsโ€‹

See the cancellation reasons of workflows in a pie chart.

type DatasetOptions.CancellationReasons = {
workflow_definition_ids?: string[]
entity_schema?: string
relative_time_range?: string
time_range_from?: string
time_range_to?: string
}

DatasetOptions.WorkflowTasksOverviewโ€‹

Get a list of tasks to help organize executing users their day.

type DatasetOptions.WorkflowTasksOverview = {
dataset: "total_count_of_workflow_executions" | "workflow_execution_time_series" | "cumulative_sum_of_workflows" | "cancellation_reasons" | "phases_count" | "phases_duration" | "tasks_duration" | "task_duration" | "workflow_tasks_overview"
workflow_definition_ids?: string[]
entity_schema?: string
relative_time_range?: string
time_range_from?: string
time_range_to?: string
assignee_ids?: string[]
include_unassigned?: boolean
due_date_from?: string
due_date_to?: string
sort_by?: string
page_number?: number
page_size?: number
}

Response.WorkflowTaskOverviewโ€‹

type Response.WorkflowTaskOverview = {
results?: Array<{
orgId?: string
id?: string
definitionId?: string
phaseId?: string
entityRefId?: string
name?: string
type?: "MANUAL" | "AUTOMATION"
ecp?: {
label?: { ... }
}
requirements?: Array<{
definitionId?: { ... }
type?: { ... }
condition?: { ... }
}>
executionType?: "MANUAL" | "AUTOMATION"
executionId?: string
assignedTo?: string[]
assignedToInProgress?: string
status?: "UNASSIGNED" | "ASSIGNED" | "COMPLETED" | "SKIPPED" | "IN_PROGRESS"
executionStatus?: "STARTED" | "DONE" | "CLOSED"
created?: string
lastUpdated?: string
dueDate?: string
dynamicDueDate?: {
numberOfUnits: { ... }
timePeriod: { ... }
actionTypeCondition?: { ... }
stepId?: { ... }
}
manuallyCreated?: boolean
enabled?: boolean
automationConfig?: {
flowId: { ... }
executionId?: { ... }
executionStatus?: { ... }
}
executionName?: string
contexts?: Array<{
id: { ... }
title: { ... }
schema: { ... }
}>
}>
hits?: number
}

ECPDetailsโ€‹

Details regarding ECP for the workflow step

type ECPDetails = {
label?: string
}

WorkflowContextโ€‹

type WorkflowContext = {
id: string
title: string
schema: string
}

WorkflowStatusโ€‹

type WorkflowStatus = "STARTED" | "DONE" | "CLOSED"

AutomationConfigโ€‹

Configuration for automation execution to run

type AutomationConfig = {
flowId: string
executionId?: string
executionStatus?: string
}

DynamicDueDateโ€‹

set a Duedate for a step then a specific

type DynamicDueDate = {
numberOfUnits: number
timePeriod: "days" | "weeks" | "months"
actionTypeCondition?: "WORKFLOW_STARTED" | "STEP_CLOSED"
stepId?: string
}

TaskStatusโ€‹

type TaskStatus = "UNASSIGNED" | "ASSIGNED" | "COMPLETED" | "SKIPPED" | "IN_PROGRESS"

TaskRequirementโ€‹

describe the requirement for step enablement

type TaskRequirement = {
definitionId?: string
type?: "STEP"
condition?: "CLOSED"
}

TaskTypeโ€‹

type TaskType = "MANUAL" | "AUTOMATION"

Taskโ€‹

type Task = {
orgId?: string
id?: string
definitionId?: string
phaseId?: string
entityRefId?: string
name?: string
type?: "MANUAL" | "AUTOMATION"
ecp?: {
label?: string
}
requirements?: Array<{
definitionId?: string
type?: "STEP"
condition?: "CLOSED"
}>
executionType?: "MANUAL" | "AUTOMATION"
executionId?: string
assignedTo?: string[]
assignedToInProgress?: string
status?: "UNASSIGNED" | "ASSIGNED" | "COMPLETED" | "SKIPPED" | "IN_PROGRESS"
executionStatus?: "STARTED" | "DONE" | "CLOSED"
created?: string
lastUpdated?: string
dueDate?: string
dynamicDueDate?: {
numberOfUnits: number
timePeriod: "days" | "weeks" | "months"
actionTypeCondition?: "WORKFLOW_STARTED" | "STEP_CLOSED"
stepId?: string
}
manuallyCreated?: boolean
enabled?: boolean
automationConfig?: {
flowId: string
executionId?: string
executionStatus?: string
}
executionName?: string
contexts?: Array<{
id: string
title: string
schema: string
}>
}

WorkflowsQueryOptions.WorkflowDefinitionIDsโ€‹

Filter by specific workflows by passing a list of workflow definition ids.

type WorkflowsQueryOptions.WorkflowDefinitionIDs = string[]

WorkflowsQueryOptions.EntitySchemaโ€‹

Workflows can be applied to different kinds of entities, e.g. on Opportunities or Orders. You can choose to limit your results to workflow executions to specific entity schemas / types.

type WorkflowsQueryOptions.EntitySchema = string

WorkflowsQueryOptions.RelativeTimeRangeโ€‹

A combination of two worde that describe a time range, e.g. "this year" or "last month"

type WorkflowsQueryOptions.RelativeTimeRange = string

WorkflowsQueryOptions.TimeRangeFromโ€‹

Set a specific start of a time range, e.g. "2023-01-01"

type WorkflowsQueryOptions.TimeRangeFrom = string

WorkflowsQueryOptions.TimeRangeToโ€‹

Set a specific end of a time range, e.g. "2023-06-30"

type WorkflowsQueryOptions.TimeRangeTo = string

WorkflowsQueryOptions.GroupTimeByโ€‹

If chosen a time series, this parameter sets by which time the data is grouped, e.g. quarterly, monthly or weekly. Available values: "D","W","M","Q","Y"

type WorkflowsQueryOptions.GroupTimeBy = string

WorkflowsQueryOptions.WorkflowStatesโ€‹

Filter by the states of the workflow executions.

type WorkflowsQueryOptions.WorkflowStates = string[]

DatasetNameโ€‹

type DatasetName = string

EntityDatasetโ€‹

type EntityDataset = "entity_operations" | "entities_timemachine" | "datalake_raw_sql"

AutomationExecutionDatasetโ€‹

type AutomationExecutionDataset = "automation_executions_overview" | "list_automation_definitions"

WorkflowDatasetโ€‹

type WorkflowDataset = "total_count_of_workflow_executions" | "workflow_execution_time_series" | "cumulative_sum_of_workflows" | "cancellation_reasons" | "phases_count" | "phases_duration" | "tasks_duration" | "task_duration" | "workflow_tasks_overview"

WorkflowStatesโ€‹

type WorkflowStates = "STARTED" | "CLOSED" | "DONE"

PhaseStatesโ€‹

type PhaseStates = "OPEN" | "COMPLETED" | "IN_PROGRESS"

TaskStatesโ€‹

type TaskStates = "OPEN" | "COMPLETED" | "IN_PROGRESS"

SortByโ€‹

type SortBy = "due_date_ascending" | "due_date_descending" | "creation_date_ascending" | "creation_date_descending"

TimeGroupsโ€‹

type TimeGroups = "Y" | "Q" | "M" | "W" | "D"

RelativeTimeRangeโ€‹

type RelativeTimeRange = "all_time" | "this_week" | "last_week" | "last_7_days" | "this_month" | "last_month" | "last_30_days" | "last_3_months" | "last_6_months" | "this_year" | "last_year"

WorkflowsQueryResultโ€‹

type WorkflowsQueryResult = {
data?: string | number | Record<string, unknown> | Record<string, unknown>[][] | Record<string, unknown> | string | number
labels?: string[]
timestamp?: string
}

AutomationExecutionResponseโ€‹

type AutomationExecutionResponse = {
hits?: number
results?: Array<{
flow_id: string
flow_name?: string
execution_id: string
execution_status: string
entity_schema?: string
entity_id?: string
created_at: string
updated_at?: string
error?: {
message?: { ... }
error_code?: { ... }
}
trigger_event?: {
type?: { ... }
trigger_type?: { ... }
}
}>
}

ListAutomationDefinitionsResponseโ€‹

type ListAutomationDefinitionsResponse = {
hits?: number
results?: Array<{
flow_id: string
flow_name: string
entity_schema?: string
}>
}

SemanticModelโ€‹

The semantic model exposing entities, relationships, and query capabilities

type SemanticModel = {
entities?: Array<{
name?: string
displayName?: string
schema?: string
}>
relationships?: Array<{
from?: string
to?: string
relationship?: "hasMany" | "belongsTo" | "hasOne"
displayName?: string
}>
capabilities?: {
aggregations?: string[]
calculationTypes?: Array<{
type?: { ... }
description?: { ... }
parameters?: { ... }
}>
granularities?: string[]
filterOperators?: Array<{
operator?: { ... }
description?: { ... }
}>
}
}

QueryResultsโ€‹

type QueryResults = {
status?: string
timestamp?: string
results?: Record<string, unknown>[]
}

TimeSeriesSettingsโ€‹

type TimeSeriesSettings = {
dataset?: "time_series"
from?: string // date-time
to?: string // date-time
time_grouper?: string
workflow_names?: string[]
}

NameDurationSettingsโ€‹

type NameDurationSettings = {
dataset?: "name_duration"
from?: string // date-time
to?: string // date-time
workflow_name?: string
}