---
title: "On Demand Tables"
method: POST
path: "/api/mdm/on_demand_tables"
tags: ["MDM"]
---

# On Demand Tables

`POST /api/mdm/on_demand_tables`

**Function**: `on_demand_tables`
**Type**: API Endpoint (POST)

**Purpose**:
This endpoint facilitates the creation and management of tables in the customer database.
It allows for the creation, alteration, and deletion of columns within a custom table based on the provided request data.

**URL**:
`POST /api/mdm/on_demand_tables`

**Request Parameters**:
- `request` (Request): The request object.
- `table_request` (TableCreateRequest): An object containing details about the table and columns to be managed.
- `Customer_Key` (Header, required): A base64 encoded string containing `lscode` and `firmcode`.
- `current_user` (str): The current user performing the operation, obtained via dependency injection.

**Process**:
1. Decodes the `Customer_Key` to extract `lscode` and `firmcode`.
2. Checks if the table exists in the metadata (`LS_Custom_Tables`). If not, it inserts a new entry.
3. Iterates over the columns in `table_request` to perform create, alter, or drop operations:
   - Creates a new column if it doesn't exist.
   - Alters an existing column's details.
   - Drops a column if specified.
4. Constructs and executes a SQL query to create the actual database table based on the processed metadata.
5. Commits the transaction and returns a response detailing the status of the operations.

**Response**:
- A JSON object containing a status message and details of each column operation performed.
- Indicates success or failure for each step, including any errors encountered.

**Exceptions**:
- Handles exceptions related to database operations and invalid customer key formats, providing appropriate error messages.

## Headers

- `Customer-Key` string, required

## Request body

- TableCreateRequest
  - `tableName` string, required
  - `deleteOption` string, required
  - `errorOption` string
  - `description` string, nullable
  - `columnList` Column[], required
    - `columnName` string, required
    - `dataType` string, required
    - `length` number, nullable
    - `scale` number, nullable
    - `pKey` boolean, required
    - `isRequired` boolean, required
    - `defaultValue` string, nullable
    - `colType` integer, required
    - `referenceType` string, nullable
    - `columnType` string, nullable
    - `oldColumnName` string, nullable

## Response `200`

Successful Response

- unknown

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.dev/leapsurgebi/apis/leapsurgeapi.md) · [All operations](https://skmtc.dev/leapsurgebi/apis/leapsurgeapi/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/leapsurgebi/leapsurgeapi/revisions/5a6b1464bfeb/schema)
