LiyaEngine Docs

Data sources

/v1/data-sources — connect a database, bucket, API or website, test it, sync it and read its history.

Dashboard

A data source keeps documents in step with a database, a bucket, a JSON API or a website. These endpoints do what Knowledge → Data sources does in the dashboard.

Which keys can call them

Key scopeList, get and historyCreate, update, delete, sync, test
fullYesYes
read and run_readYesNo
runtimeNoNo

Endpoints

GET    /v1/data-sources
POST   /v1/data-sources
POST   /v1/data-sources/test
GET    /v1/data-sources/{id}
PATCH  /v1/data-sources/{id}
DELETE /v1/data-sources/{id}?delete_documents=false
POST   /v1/data-sources/{id}/sync
GET    /v1/data-sources/{id}/runs

Create one

curl -X POST https://api.liyaengine.ai/v1/data-sources \
  -H "Authorization: Bearer $LIYA_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "provider": "postgres",
    "name": "Support articles",
    "config": {
      "host": "db.example.com", "database": "kb", "user": "reader", "ssl": "verify",
      "table": "public.articles", "id_field": "id", "title_field": "title", "content_fields": ["body"]
    },
    "secret": { "password": "..." },
    "collection_ids": ["col_..."],
    "frequency": "daily"
  }'

provider is postgres, mysql, s3, rest_api or web_crawl. Saving does not sync. Call POST /v1/data-sources/{id}/sync, or set a frequency, which syncs it soon after saving.

config by provider

Providerconfig fields
postgres, mysqlhost, port, database, user, ssl (verify or require), either table or a read-only query, id_field, title_field or title_template, content_fields or content_template, max_rows
s3bucket, prefix, region, endpoint (HTTPS, for S3-compatible storage), extensions, max_objects
rest_apiurl, headers, query, auth (none, bearer, header, basic), pagination (none, page, offset, cursor, link), items_path, id_field, title and content mapping, max_pages, max_items
web_crawlurl, depth (0 to 3), max_pages, include, exclude

A template such as "{{first}} {{last}}" fills in fields from the record, and a.b reaches into nested fields.

secret by provider

Providersecret
postgres, mysql{ "password": "..." }
s3{ "access_key_id": "...", "secret_access_key": "..." }
rest_api{ "value": "..." }: the token, key or password, as auth says
web_crawlnot used

Credentials are encrypted at rest and are never returned: responses carry has_secret: true. On PATCH, leave secret out to keep the saved credentials.

Common fields

Field
nameUnique within the workspace (409 DATA_SOURCE_NAME_TAKEN).
collection_idsWhere the documents go. Changing them later moves existing documents.
indexingHow to split the documents. See Splitting and re-indexing.
frequencymanual (default), hourly, every_6_hours, daily, weekly.
delete_missingRemove a document when the source stops listing it. Default true.

Test before saving

POST /v1/data-sources/test takes provider, config and secret (or data_source_id to reuse a saved source's credentials) and returns:

{
  "ok": true,
  "message": "Connected. 4 columns found.",
  "preview": [{ "external_id": "1", "name": "How refunds work", "text": "body: Refunds are issued within 30 days...", "words": 17 }],
  "truncated": true
}

A connection that fails returns ok: false and a message that says why. Nothing is saved.

Sync and history

POST /v1/data-sources/{id}/sync starts a sync and returns 202 at once. A source that is already syncing returns 409 SYNC_IN_PROGRESS. Follow it in GET /v1/data-sources/{id}/runs:

{ "runs": [{ "id": "...", "status": "completed", "trigger": "automatic", "added": 3, "updated": 2, "unchanged": 40, "removed": 1, "failed": 0, "truncated": false, "problems": [] }] }

truncated: true means the run did not read the whole source, so nothing was removed.

Delete

DELETE keeps the source's documents as ordinary documents. Pass delete_documents=true to delete them too. A source that is syncing returns 409 SYNC_IN_PROGRESS.

What a data source will not reach

Database, bucket and API addresses must be public. Private and internal networks, localhost and cloud metadata addresses are refused, and an API request is HTTPS only.

On this page