---
title: "Table Dml"
method: POST
path: "/api/new_mdm/table_dml"
tags: ["MDM NEW"]
---

# Table Dml

`POST /api/new_mdm/table_dml`

**Function**: `table_dml`

**Type**: API Endpoint (POST)

**Purpose**:  
Executes data manipulation operations (insert, update, delete) on a specified table in the customer database based on the provided input data.

**URL**:  
`POST /api/new_mdm/table_dml`

**Request Headers**:
- `Customer_Key` (str, required): A base64 encoded string containing `lscode` and `firmcode` for the customer. This must be decoded for database access.

**Request Body**:
- `input_data` (TableDMLRequest, required): Contains the table name and lists of data for insert, update, and delete operations.

**Response**:
- Returns a JSON object with a success message if the operations are successful.

**Exceptions**:
- Handles exceptions related to invalid customer key format, missing `idx` for update/delete operations, and database errors, providing appropriate error messages.

**Steps**:
1. **Customer Key Decoding**:  
   Decodes the `Customer_Key` to extract the `lscode` and `firmcode`. Raises an error if the format is invalid.

2. **Input Validation**:  
   Validates the presence of `table_name` and that the data for insert, update, and delete operations are in list format.

3. **Database Connection**:  
   Establishes a connection to the database using `custCursorConnection`.

4. **Data Manipulation**:  
   Executes insert, update, and delete operations on the specified table using the input data.

5. **Transaction Handling**:  
   Commits the transaction if all operations are successful, or rolls back in case of an error.

6. **Logging**:  
   Logs the API call with details of the operation.

7. **Response Construction**:  
   Returns a success message or error details based on the outcome of the operations.

## Headers

- `Customer-Key` string, required

## Request body

- TableDMLRequest
  - `user` string, required — The user performing the operation
  - `time` string, required — The time of the operation
  - `table_name` string, required — The name of the table to perform operations on
  - `insertValue` object[] — List of records to insert
  - `updateValue` object[] — List of records to update
  - `deleteValue` object[] — List of records to delete

## Response `200`

Successful Response

- object

## 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)
