Skip to main content
curl --request POST \
  --url https://api.usedatabrain.com/api/v2/data-app/datamarts/semantic-layer \
  --header 'Authorization: Bearer dbn_live_abc123...' \
  --header 'Content-Type: application/json' \
  --data '{
    "datamartName": "sales-analytics",
    "tables": [
      {
        "name": "orders",
        "description": "Customer purchase orders",
        "synonyms": ["purchases", "transactions"],
        "columns": [
          {
            "name": "order_id",
            "description": "Unique order identifier",
            "columnType": "Identifier",
            "isIdentifier": true
          },
          {
            "name": "status",
            "description": "Current order status",
            "synonyms": ["order status", "state"],
            "columnType": "ENUM"
          },
          {
            "name": "amount",
            "description": "Total order amount in USD",
            "columnType": "Number"
          }
        ]
      }
    ],
    "feedback": "This datamart covers e-commerce sales data. All amounts are in USD."
  }'
{
  "id": "sales-analytics"
}
POST
/
api
/
v2
/
data-app
/
datamarts
/
semantic-layer
curl --request POST \
  --url https://api.usedatabrain.com/api/v2/data-app/datamarts/semantic-layer \
  --header 'Authorization: Bearer dbn_live_abc123...' \
  --header 'Content-Type: application/json' \
  --data '{
    "datamartName": "sales-analytics",
    "tables": [
      {
        "name": "orders",
        "description": "Customer purchase orders",
        "synonyms": ["purchases", "transactions"],
        "columns": [
          {
            "name": "order_id",
            "description": "Unique order identifier",
            "columnType": "Identifier",
            "isIdentifier": true
          },
          {
            "name": "status",
            "description": "Current order status",
            "synonyms": ["order status", "state"],
            "columnType": "ENUM"
          },
          {
            "name": "amount",
            "description": "Total order amount in USD",
            "columnType": "Number"
          }
        ]
      }
    ],
    "feedback": "This datamart covers e-commerce sales data. All amounts are in USD."
  }'
{
  "id": "sales-analytics"
}
Add semantic metadata to a datamart that doesn’t have a semantic layer yet. This includes table and column descriptions, synonyms, column type classifications, and global feedback for AI context.
This endpoint will reject the request with 409 SEMANTIC_LAYER_ALREADY_EXISTS if the datamart already has semantic data. Use PUT to modify an existing semantic layer.
At least one of tables or feedback must be provided in the request body.

Authentication

This endpoint requires a service token in the Authorization header. Data app API tokens are not permitted and will be rejected with a 403 error. To access your service token:
  1. Go to your Databrain dashboard and open Settings.
  2. Navigate to Settings.
  3. Find the Service Tokens section.
  4. Click the “Generate Token” button to generate a new service token if you don’t have one already.
Use this token as the Bearer value in your Authorization header.

Headers

Authorization
string
required
Bearer token for API authentication. Use your service token.
Authorization: Bearer dbn_live_abc123...
Content-Type
string
required
Must be set to application/json for all requests.
Content-Type: application/json

Request Body

datamartName
string
required
Name of the existing datamart to create a semantic layer for. Must match exactly (case-sensitive).
tables
array
Array of table objects with semantic metadata. Each table must reference a table that exists in the datamart.
tables.name
string
required
Table name from the datamart. Must match an existing table.
tables.schemaName
string
Optional schema name for the table.
tables.description
string
Human-readable description of the table. Maximum 500 characters.
tables.synonyms
string[]
Alternative names for the table. Maximum 10 synonyms, each up to 100 characters. Must be unique (case-insensitive).
tables.miscellaneousInfo
string
Additional context for AI query generation. Maximum 1000 characters.
tables.columns
array
Array of column objects with semantic metadata.
tables.columns.name
string
required
Column name from the table. Must match an existing column.
tables.columns.description
string
Human-readable description of the column. Maximum 500 characters.
tables.columns.synonyms
string[]
Alternative names for the column. Maximum 10 synonyms, each up to 100 characters. Must be unique (case-insensitive).
tables.columns.miscellaneousInfo
string
Additional context for AI query generation. Maximum 1000 characters.
tables.columns.columnType
string
Semantic column type classification. Must be one of: String, Long String, String (Custom), ENUM, Mapper, Range, Expression, Identifier, Number, JSON.
tables.columns.columnTypeConfig
object | string | null
Additional configuration for the column type. Must match the shape expected for columnType:
  • String, String (Custom), ENUM, Mapper: plain object mapping values to descriptions (e.g. { "pending": "Not shipped", "shipped": "Sent" })
  • Range: { "lowerLimit": number, "upperLimit": number } (both must be numbers)
  • Expression: string template
  • JSON: string (sample JSON)
  • Identifier, Number, Long String: omit or use null (non-null config is rejected)
tables.columns.isIdentifier
boolean
Mark this column as an identifier (e.g., primary key, foreign key). Defaults to false.
tables.columns.isNotIndexed
boolean
Exclude this column from AI indexing. Defaults to false.
feedback
string
Global feedback text providing context to the AI about this datamart. Maximum 2000 characters.

Response

On success, the response body contains only the datamart name. There is no error field in the JSON body when the request succeeds.
id
string
The name of the datamart (same as the input datamartName) on success.

Examples

HTTP Status Code Summary

Status CodeDescription
200OK — Semantic layer created successfully
400Bad Request — Validation failed (see error codes below)
401Unauthorized — Invalid or missing API token
403Forbidden — Data app token used instead of service token
409Conflict — Semantic layer already exists on this datamart
500Internal Server Error — Server error occurred

Possible Errors

Error CodeHTTP StatusDescription
INVALID_REQUEST_BODY400Missing required fields or validation failure
INVALID_DATAMART400Datamart not found
INVALID_TABLE400Table name doesn’t exist in the datamart
INVALID_COLUMN400Column name doesn’t exist in the table
INVALID_COLUMN_TYPE400Column type incompatible with the column’s datatype
INVALID_COLUMN_TYPE_CONFIG400Column type config has wrong shape for the column type
DUPLICATE_SYNONYM400Duplicate synonyms detected (case-insensitive)
SEMANTIC_LAYER_ALREADY_EXISTS409Datamart already has semantic data — use PUT to update
AUTHENTICATION_ERROR403Data app token used instead of service token
INTERNAL_SERVER_ERROR500Server error

Quick Start Guide

1

Verify your datamart exists

Use the List Datamarts API to confirm the datamart exists and note its exact name.
2

Prepare your semantic metadata

Gather descriptions, synonyms, and column type classifications for your tables:
{
  "datamartName": "sales-analytics",
  "tables": [
    {
      "name": "orders",
      "description": "Customer purchase orders",
      "synonyms": ["purchases"],
      "columns": [
        { "name": "order_id", "description": "Unique identifier", "columnType": "Identifier" },
        { "name": "amount", "description": "Total in USD", "columnType": "Number" }
      ]
    }
  ],
  "feedback": "All monetary values are in USD."
}
3

Create the semantic layer

curl --request POST \
  --url https://api.usedatabrain.com/api/v2/data-app/datamarts/semantic-layer \
  --header 'Authorization: Bearer dbn_live_abc123...' \
  --header 'Content-Type: application/json' \
  --data '{ ... }'
4

Verify with GET

Retrieve the semantic layer to confirm it was created and check the completion score:
curl --request GET \
  --url 'https://api.usedatabrain.com/api/v2/data-app/datamarts/semantic-layer?datamartName=sales-analytics' \
  --header 'Authorization: Bearer dbn_live_abc123...'

Next Steps

Get Semantic Layer

Retrieve and inspect your semantic layer

Update Semantic Layer

Modify your semantic layer after creation

Delete Semantic Layer

Remove semantic layer metadata

Semantic Layer Guide

Configure the semantic layer in the Databrain UI