---
title: "Searchlist"
method: POST
path: "/api/new_mdm/search_list"
tags: ["MDM NEW"]
---

# Searchlist

`POST /api/new_mdm/search_list`

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

**Purpose**:  
The function searches for a list of values based on specified conditions from a given table and column in the customer database.

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

**Request Headers**:
- `customer_key` (str, required): An encoded string that contains the `lscode` and `firmcode` for the customer, which must be decoded for further processing.

**Request Body**:
```json
{
    "table": "<Table Name>",
    "column": "<colName>",
    "filter": "<filter>",
    "condition": "<condition>"
}
```

**Response Example**:
```json
[
    {"Custom4": "<Customer>"}
]
```

**Steps**:
1. **Log Creation**:  
A unique log ID is generated based on the current date and time, ensuring traceability for each request.

2. **Customer Key Decoding**:  
The `customer_key` is decoded using base64. If the decoded value is invalid or improperly formatted, the function returns an error response.

3. **Request Body Parsing**:  
The function retrieves the `table`, `column`, `filter`, and `condition` from the request body to use in the SQL query.

4. **Database Connection**:  
Using the decoded values, a connection to the customer-specific database is established with the `custCursorConnection` function.

5. **SQL Query Construction**:  
A SQL query is dynamically constructed based on the input parameters, including the specified table, column, filter, and condition. The query is executed to fetch the relevant records.

6. **Response Construction**:  
The results from the query execution are formatted into a list of dictionaries and returned as a JSON response.

**Error Handling**:
- **Invalid Customer Key**:  
If the decoded customer key is empty or does not follow the expected format, an appropriate error message is returned.
- **Invalid Request Body**:  
If any required fields in the request body are missing, an error response is returned.
- **Database Errors**:  
Any exceptions during query execution are caught, logged, and a `500` status response is returned with error details.

**Security Considerations**:
- The `customer_key` is encoded to protect sensitive information like `lscode` and `firmcode`.

**Error Response Example**:
```json
{
    "status": "failed",
    "message": "Invalid Customer Key"
}
```

```json
{
    "status": "failed",
    "message": "Invalid request body"
}
```

```json
{
    "status": "failed",
    "message": {
        "error_type": "OperationalError",
        "message": "SQL syntax error"
    }
}
```

## Headers

- `customer-key` string, required

## Request body

- MdmSearchValues
  - `table` string, required
  - `column` string, required
  - `filter` string, nullable, required
  - `condition` string, nullable, required

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