Table Columns

https://{your-workspace-slug}.xata.sh/db/{db_branch_name}/tables/{table_name}/columns/

This endpoint allows working with a table's columns.

Expected Parameters
NameDescriptionInRequiredSchema
db_branch_nameThe DBBranchName matches the pattern `{db_name}:{branch_name}`. pathstring
table_nameThe Table namepathstring

Get the Columns

GET  https://{your-workspace-slug}.xata.sh/db/{db_branch_name}/tables/{table_name}/columns/

Retrieves the list of table columns and their definition. This endpoint returns the column list with object columns being reported with their full dot-separated path (flattened).

Possible Responses
Status CodeDescriptionExample Response/Type Definition
200OK
{
  "columns": [
    {
      "name": "name",
      "type": "string"
    },
    {
      "name": "email",
      "type": "email"
    },
    {
      "name": "settings.plan",
      "type": "string"
    },
    {
      "name": "settings.dark",
      "type": "bool"
    }
  ]
}
400Bad Request
type GetTableColumns = {
    id?: string;
    message: string;
};
401Authentication Error
{
  "message": "invalid API key"
}
404Example response
type GetTableColumns = {
    id?: string;
    message: string;
};
5XXUnexpected Error

Creates a New Column

POST  https://{your-workspace-slug}.xata.sh/db/{db_branch_name}/tables/{table_name}/columns/

Adds a new column to the table. The body of the request should contain the column definition. In the column definition, the 'name' field should contain the full path separated by dots. If the parent objects do not exists, they will be automatically created. For example, passing "name": "address.city" will auto-create the address object if it doesn't exist.

Request Body Example
{
  "name": "columnName",
  "type": "string"
}
Request Body Type Definition
/**
 * @example {"name":"columnName","type":"string"}
 */
type AddTableColumn = Column;

type Column = {
    name: string;
    type: "bool" | "int" | "float" | "string" | "text" | "email" | "multiple" | "link" | "object" | "datetime";
    link?: {
        table: string;
    };
    columns?: Column[];
};
Possible Responses
Status CodeDescriptionExample Response/Type Definition
200Returns the migration ID.
{
  "migrationID": "mig_c7m19ilcefoebpqj12p0"
}
400Bad Request
type AddTableColumn = {
    id?: string;
    message: string;
};
401Authentication Error
{
  "message": "invalid API key"
}
404Example response
type AddTableColumn = {
    id?: string;
    message: string;
};
5XXUnexpected Error