Skip to main content

Data Governance API

Usageโ€‹

import { epilot } from '@epilot/sdk'

epilot.authorize(() => '<token>')
const { data } = await epilot.dataGovernance.queryEntities(...)

Tree-shakeable importโ€‹

import { getClient, authorize } from '@epilot/sdk/data-governance'

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

Operationsโ€‹

Query

Auditable Jobs

Data Lifecycle Configs

Schemas

queryEntitiesโ€‹

Query entities matching a data lifecycle config

POST /data-governance/v1/{entity_schema}/query

const { data } = await client.queryEntities(
{
entity_schema: 'example',
},
{
saved_view_id: 'string',
include_deleted: 'true',
filters: [
{
type: 'entity_workflows_only_in_closed_or_cancelled_status',
related_entity_schemas: ['string'],
lookback_period_days: 0,
message_type: ['SENT'],
workflow_status: ['CLOSED']
}
],
from: 0,
size: 0,
hydrate: true,
fields: ['string']
},
)
Response
{
"hits": 0,
"results": [
{}
]
}

createJobโ€‹

Create a new job run

POST /data-governance/v1/{entity_schema}/jobs

const { data } = await client.createJob(
{
entity_schema: 'example',
},
{
type: 'deletion',
config_id: 'string',
scheduled_for: '1970-01-01',
status: 'in_progress',
started_at: '1970-01-01T00:00:00.000Z'
},
)
Response
{
"id": "string",
"type": "deletion",
"config_id": "string",
"entity_schema": "string",
"scheduled_for": "1970-01-01",
"status": "in_progress",
"details": {},
"started_at": "1970-01-01T00:00:00.000Z",
"completed_at": "1970-01-01T00:00:00.000Z",
"error": "string",
"report": {
"bucket": "string",
"key": "string",
"format": "csv"
},
"created_at": "1970-01-01T00:00:00.000Z",
"last_updated_at": "1970-01-01T00:00:00.000Z",
"trigger": "schedule",
"triggered_by": "string"
}

updateJobโ€‹

Update an existing job run

PATCH /data-governance/v1/{entity_schema}/jobs/{job_id}

const { data } = await client.updateJob(
{
entity_schema: 'example',
job_id: 'example',
},
{
status: 'in_progress',
details: {},
completed_at: '1970-01-01T00:00:00.000Z',
error: 'string',
report: {
bucket: 'string',
key: 'string',
format: 'csv'
}
},
)
Response
{
"id": "string",
"type": "deletion",
"config_id": "string",
"entity_schema": "string",
"scheduled_for": "1970-01-01",
"status": "in_progress",
"details": {},
"started_at": "1970-01-01T00:00:00.000Z",
"completed_at": "1970-01-01T00:00:00.000Z",
"error": "string",
"report": {
"bucket": "string",
"key": "string",
"format": "csv"
},
"created_at": "1970-01-01T00:00:00.000Z",
"last_updated_at": "1970-01-01T00:00:00.000Z",
"trigger": "schedule",
"triggered_by": "string"
}

getJobโ€‹

Get a job by ID

GET /data-governance/v1/jobs/{job_id}

const { data } = await client.getJob({
job_id: 'example',
})
Response
{
"id": "string",
"type": "deletion",
"config_id": "string",
"entity_schema": "string",
"scheduled_for": "1970-01-01",
"status": "in_progress",
"details": {},
"started_at": "1970-01-01T00:00:00.000Z",
"completed_at": "1970-01-01T00:00:00.000Z",
"error": "string",
"report": {
"bucket": "string",
"key": "string",
"format": "csv"
},
"created_at": "1970-01-01T00:00:00.000Z",
"last_updated_at": "1970-01-01T00:00:00.000Z",
"trigger": "schedule",
"triggered_by": "string"
}

getJobReportUrlโ€‹

Get report download URL for a job

GET /data-governance/v1/jobs/{job_id}/report-url

const { data } = await client.getJobReportUrl({
job_id: 'example',
})
Response
{
"url": "string",
"expires_in": 0
}

getConfigโ€‹

Get a config by ID

GET /data-governance/v1/configs/{config_id}

const { data } = await client.getConfig({
config_id: 'example',
})
Response
{
"id": "string",
"type": "deletion",
"entity_schema": "string",
"query": {
"saved_view_id": "string",
"include_deleted": "true",
"filters": [
{
"type": "entity_workflows_only_in_closed_or_cancelled_status",
"related_entity_schemas": ["string"],
"lookback_period_days": 0,
"message_type": ["SENT"],
"workflow_status": ["CLOSED"]
}
]
},
"schedule": {
"frequency": "interval",
"interval_days": 1,
"start_date": "1970-01-01",
"end_date": "1970-01-01"
},
"enabled": true,
"created_at": "1970-01-01T00:00:00.000Z",
"last_updated_at": "1970-01-01T00:00:00.000Z",
"next_run_at": "1970-01-01",
"relations_for_deletion": ["contact"],
"last_run_at": "1970-01-01T00:00:00.000Z"
}

createJobForConfigโ€‹

Trigger a manual job run for a config

POST /data-governance/v1/configs/{config_id}/jobs

const { data } = await client.createJobForConfig({
config_id: 'example',
})
Response
{
"id": "string",
"type": "deletion",
"config_id": "string",
"entity_schema": "string",
"scheduled_for": "1970-01-01",
"status": "in_progress",
"details": {},
"started_at": "1970-01-01T00:00:00.000Z",
"completed_at": "1970-01-01T00:00:00.000Z",
"error": "string",
"report": {
"bucket": "string",
"key": "string",
"format": "csv"
},
"created_at": "1970-01-01T00:00:00.000Z",
"last_updated_at": "1970-01-01T00:00:00.000Z",
"trigger": "schedule",
"triggered_by": "string"
}

upsertConfigโ€‹

Create or update a data lifecycle config

POST /data-governance/v1/{entity_schema}/configs

const { data } = await client.upsertConfig(
{
entity_schema: 'example',
},
{
type: 'deletion',
query: {
saved_view_id: 'string',
include_deleted: 'true',
filters: [
{
type: 'entity_workflows_only_in_closed_or_cancelled_status',
related_entity_schemas: ['string'],
lookback_period_days: 0,
message_type: ['SENT'],
workflow_status: ['CLOSED']
}
]
},
schedule: {
frequency: 'interval',
interval_days: 1,
start_date: '1970-01-01',
end_date: '1970-01-01'
},
relations_for_deletion: ['contact'],
enabled: true
},
)
Response
{
"id": "string",
"type": "deletion",
"entity_schema": "string",
"query": {
"saved_view_id": "string",
"include_deleted": "true",
"filters": [
{
"type": "entity_workflows_only_in_closed_or_cancelled_status",
"related_entity_schemas": ["string"],
"lookback_period_days": 0,
"message_type": ["SENT"],
"workflow_status": ["CLOSED"]
}
]
},
"schedule": {
"frequency": "interval",
"interval_days": 1,
"start_date": "1970-01-01",
"end_date": "1970-01-01"
},
"enabled": true,
"created_at": "1970-01-01T00:00:00.000Z",
"last_updated_at": "1970-01-01T00:00:00.000Z",
"next_run_at": "1970-01-01",
"relations_for_deletion": ["contact"],
"last_run_at": "1970-01-01T00:00:00.000Z"
}

listConfigsโ€‹

List data lifecycle configs

GET /data-governance/v1/configs

const { data } = await client.listConfigs({
limit: 1,
cursor: 'example',
entity_schema: 'example',
type: 'example',
next_run_at: 'example',
enabled: true,
})
Response
{
"configs": [
{
"id": "string",
"type": "deletion",
"entity_schema": "string",
"query": {
"saved_view_id": "string",
"include_deleted": "true",
"filters": [
{
"type": "entity_workflows_only_in_closed_or_cancelled_status",
"related_entity_schemas": ["string"],
"lookback_period_days": 0,
"message_type": ["SENT"],
"workflow_status": ["CLOSED"]
}
]
},
"schedule": {
"frequency": "interval",
"interval_days": 1,
"start_date": "1970-01-01",
"end_date": "1970-01-01"
},
"enabled": true,
"created_at": "1970-01-01T00:00:00.000Z",
"last_updated_at": "1970-01-01T00:00:00.000Z",
"next_run_at": "1970-01-01",
"relations_for_deletion": ["contact"],
"last_run_at": "1970-01-01T00:00:00.000Z"
}
],
"cursor": "string"
}

listJobsโ€‹

List job runs

GET /data-governance/v1/jobs

const { data } = await client.listJobs({
limit: 1,
cursor: 'example',
entity_schema: 'example',
type: 'example',
status: 'example',
config_id: 'example',
})
Response
{
"jobs": [
{
"id": "string",
"type": "deletion",
"config_id": "string",
"entity_schema": "string",
"scheduled_for": "1970-01-01",
"status": "in_progress",
"details": {},
"started_at": "1970-01-01T00:00:00.000Z",
"completed_at": "1970-01-01T00:00:00.000Z",
"error": "string",
"report": {
"bucket": "string",
"key": "string",
"format": "csv"
},
"created_at": "1970-01-01T00:00:00.000Z",
"last_updated_at": "1970-01-01T00:00:00.000Z",
"trigger": "schedule",
"triggered_by": "string"
}
],
"cursor": "string"
}

Schemasโ€‹

ConfigTypeโ€‹

The governance action type. Determines what operation is performed on matched entities when a job runs. Currently only deletion is supported.

type ConfigType = "deletion"

JobStatusโ€‹

Current execution status of a job run.

  • in_progress โ€” the job is actively processing entities.
  • success โ€” the job completed without critical errors.
  • failed โ€” the job terminated due to an error.
type JobStatus = "in_progress" | "success" | "failed"

JobTriggerโ€‹

Indicates how the job was initiated.

  • schedule โ€” automatically created by the background scheduler.
  • manual โ€” explicitly triggered by a user via the API.
type JobTrigger = "schedule" | "manual"

JobReportFormatโ€‹

File format of the job report. Currently only CSV is supported.

type JobReportFormat = "csv"

JobReportโ€‹

Reference to a report file stored in S3 that details the outcome of a job run (e.g., which entities were deleted or failed).

type JobReport = {
bucket?: string
key?: string
format?: "csv"
}

CreateJobRequestโ€‹

Request payload for creating a new job run.

type CreateJobRequest = {
type: "deletion"
config_id: string
scheduled_for: string // date
status?: "in_progress" | "success" | "failed"
started_at?: string // date-time
}

JobDetailsโ€‹

Type-specific job outcome payload. The shape depends on the config type. For deletion jobs, typical fields include:

  • matched_count โ€” total entities matched by the query
  • deleted_count โ€” entities successfully deleted
  • failed_count โ€” entities that could not be deleted
type JobDetails = Record<string, unknown>

UpdateJobRequestโ€‹

Partial update payload for an existing job. Only the fields provided will be merged into the job record.

type UpdateJobRequest = {
status?: "in_progress" | "success" | "failed"
details?: Record<string, unknown>
completed_at?: string // date-time
error?: string
report?: {
bucket?: string
key?: string
format?: "csv"
}
}

Jobโ€‹

Represents a single execution run of a data lifecycle config. Tracks the full lifecycle from creation through completion, including outcome details and an optional downloadable report.

type Job = {
id: string
type: "deletion"
config_id: string
entity_schema: string
scheduled_for: string // date
status: "in_progress" | "success" | "failed"
details?: Record<string, unknown>
started_at?: string // date-time
completed_at?: string // date-time
error?: string
report?: {
bucket?: string
key?: string
format?: "csv"
}
created_at: string // date-time
last_updated_at: string // date-time
trigger?: "schedule" | "manual"
triggered_by?: string
}

ListJobsResponseโ€‹

Paginated response containing a list of job runs.

type ListJobsResponse = {
jobs?: Array<{
id: string
type: "deletion"
config_id: string
entity_schema: string
scheduled_for: string // date
status: "in_progress" | "success" | "failed"
details?: Record<string, unknown>
started_at?: string // date-time
completed_at?: string // date-time
error?: string
report?: {
bucket?: { ... }
key?: { ... }
format?: { ... }
}
created_at: string // date-time
last_updated_at: string // date-time
trigger?: "schedule" | "manual"
triggered_by?: string
}>
cursor?: string
}

JobReportUrlResponseโ€‹

Contains a time-limited pre-signed URL to download a job report.

type JobReportUrlResponse = {
url?: string
expires_in?: number
}

QueryFilterTypeโ€‹

Predefined data governance filter types that can be layered on top of a saved view to narrow down target entities:

  • entity_workflows_only_in_closed_or_cancelled_status โ€” include only entities whose own workflows are all in a closed/cancelled state.
  • no_related_entities โ€” include only entitie
type QueryFilterType = "entity_workflows_only_in_closed_or_cancelled_status" | "no_related_entities" | "related_entities_all_in_closed_or_cancelled_status" | "related_entities_workflows_only_in_closed_or_cancelled_status" | "no_email_communication_since"

QueryFilterโ€‹

A single governance filter condition applied during entity querying. The required and optional fields depend on the type.

type QueryFilter = {
type: "entity_workflows_only_in_closed_or_cancelled_status" | "no_related_entities" | "related_entities_all_in_closed_or_cancelled_status" | "related_entities_workflows_only_in_closed_or_cancelled_status" | "no_email_communication_since"
related_entity_schemas?: string[]
lookback_period_days?: number
message_type?: "SENT" | "RECEIVED"[]
workflow_status?: "CLOSED" | "DONE"[]
}

QueryConfigโ€‹

Defines the query used by a data lifecycle config to identify target entities. Combines a saved view with optional governance filters.

type QueryConfig = {
saved_view_id: string
include_deleted?: "true" | "false" | "only"
filters?: Array<{
type: "entity_workflows_only_in_closed_or_cancelled_status" | "no_related_entities" | "related_entities_all_in_closed_or_cancelled_status" | "related_entities_workflows_only_in_closed_or_cancelled_status" | "no_email_communication_since"
related_entity_schemas?: string[]
lookback_period_days?: number
message_type?: "SENT" | "RECEIVED"[]
workflow_status?: "CLOSED" | "DONE"[]
}>
}

QueryEntitiesRequestโ€‹

Request body for the query endpoint. Extends QueryConfig with pagination and projection options.

type QueryEntitiesRequest = {
saved_view_id: string
include_deleted?: "true" | "false" | "only"
filters?: Array<{
type: "entity_workflows_only_in_closed_or_cancelled_status" | "no_related_entities" | "related_entities_all_in_closed_or_cancelled_status" | "related_entities_workflows_only_in_closed_or_cancelled_status" | "no_email_communication_since"
related_entity_schemas?: string[]
lookback_period_days?: number
message_type?: "SENT" | "RECEIVED"[]
workflow_status?: "CLOSED" | "DONE"[]
}>
from?: number
size?: number
hydrate?: boolean
fields?: string[]
}

QueryEntitiesResultโ€‹

Response from the entity query endpoint.

type QueryEntitiesResult = {
hits?: number
results?: Record<string, unknown>[]
}

ConfigScheduleโ€‹

Interval-based schedule. The governance engine will create a job every interval_days days, optionally bounded by start and end dates.

type ConfigSchedule = {
frequency: "interval"
interval_days: number
start_date?: string // date
end_date?: string // date
}

IntervalConfigScheduleโ€‹

Interval-based schedule. The governance engine will create a job every interval_days days, optionally bounded by start and end dates.

type IntervalConfigSchedule = {
frequency: "interval"
interval_days: number
start_date?: string // date
end_date?: string // date
}

UpsertConfigRequestโ€‹

Request payload for creating or updating a data lifecycle config.

type UpsertConfigRequest = {
type: "deletion"
query: {
saved_view_id: string
include_deleted?: "true" | "false" | "only"
filters?: Array<{
type: { ... }
related_entity_schemas?: { ... }
lookback_period_days?: { ... }
message_type?: { ... }
workflow_status?: { ... }
}>
}
schedule: {
frequency: "interval"
interval_days: number
start_date?: string // date
end_date?: string // date
}
relations_for_deletion?: "contact" | "file" | "opportunity" | "order" | "meter" | "ticket" | "message" | "account" | "submission" | "contract"[]
enabled?: boolean
}

Configโ€‹

A data lifecycle config defining an automated policy (e.g., scheduled entity deletion) for a specific entity schema.

type Config = {
id: string
type: "deletion"
entity_schema: string
query: {
saved_view_id: string
include_deleted?: "true" | "false" | "only"
filters?: Array<{
type: { ... }
related_entity_schemas?: { ... }
lookback_period_days?: { ... }
message_type?: { ... }
workflow_status?: { ... }
}>
}
schedule?: {
frequency: "interval"
interval_days: number
start_date?: string // date
end_date?: string // date
}
enabled?: boolean
created_at?: string // date-time
last_updated_at?: string // date-time
next_run_at?: string // date
relations_for_deletion?: "contact" | "file" | "opportunity" | "order" | "meter" | "ticket" | "message" | "account" | "submission" | "contract"[]
last_run_at?: string // date-time
}

DeletionRelationEntitySchemaโ€‹

Entity schema slug that can be specified as a cascading deletion target. When a primary entity is deleted, related entities of these schemas are also removed.

type DeletionRelationEntitySchema = "contact" | "file" | "opportunity" | "order" | "meter" | "ticket" | "message" | "account" | "submission" | "contract"

ListConfigsResponseโ€‹

Paginated response containing a list of data lifecycle configs.

type ListConfigsResponse = {
configs?: Array<{
id: string
type: "deletion"
entity_schema: string
query: {
saved_view_id: { ... }
include_deleted?: { ... }
filters?: { ... }
}
schedule?: {
frequency: { ... }
interval_days: { ... }
start_date?: { ... }
end_date?: { ... }
}
enabled?: boolean
created_at?: string // date-time
last_updated_at?: string // date-time
next_run_at?: string // date
relations_for_deletion?: "contact" | "file" | "opportunity" | "order" | "meter" | "ticket" | "message" | "account" | "submission" | "contract"[]
last_run_at?: string // date-time
}>
cursor?: string
}