---
title: "Existing User"
method: GET
path: "/api/mdm/existing_user"
tags: ["MDM"]
---

# Existing User

`GET /api/mdm/existing_user`

**Function**: `existing_user`  
**Type**: API Endpoint (GET)

**Purpose**:  
This function retrieves existing user details, menu access, and table access for a given user based on the provided headers. It decodes the Customer_Key to identify the customer and database, fetches user-related information, and constructs a structured response.

**URL**:  
`GET /api/mdm/existing_user`

**Headers**:
- `Aad-Id` (str, required): A base64-encoded string representing the AAD ID of the user.  
- `Customer-Key` (str, required): A base64-encoded string containing information to identify the customer and database.
- `User-Code` (str, required): A base64-encoded string representing the user code.
- `App-Code` (str, required): A base64-encoded string representing the application code.

**Response Model**:  
Returns an `ExistingUser` instance containing the user details, menu access, and table access information.

**Response Example**:
```json
{
    "user": {
        "first_name": "<first_name>",
        "last_name": "<last_name>",
        "email": "<email>",
        "mobile": "<mobile>",
        "user_group_code": "<user_group_code>",
        "user_role": "<user_role>",
        "active": <active>
    },
    "menu_access": [
        {
            "parent": {
                "menu_code": "<menu_code>",
                "menu_name": "<menu_name>",
                "access": <access>
            },
            "children": [
                {
                    "menu_code": "<menu_code>",
                    "menu_name": "<menu_name>",
                    "access": <access>
                }
            ]
        }
    ],
    "table_access": [
        {
            "table_name": "<table_name>",
            "access": <access>,
            "upload_download_access": <upload_download_access>
        }
    ]
}
```

**Error Handling**:
- Returns HTTP 400 if `Customer_Key` is invalid.
- Returns HTTP 404 if the user is not found.
- Returns HTTP 500 for any unexpected server errors.

**Steps**:
1. Decode the `Customer_Key` header and validate its format.
2. Extract and decode the `userCode` and `appCode`.
3. Fetch user details, group details, menu access, and table access from the database.
4. Construct and return the structured response.
5. Log the API call with a unique log identifier for tracking.

## Headers

- `Customer-Key` string, required
- `User-Code` string, required
- `App-Code` string, required

## Response `200`

Successful Response

- ExistingUser
  - `user` UserResponse, required
    - `first_name` string, required
    - `last_name` string, required
    - `email` string, required
    - `mobile` string, required
    - `user_group_code` string, required
    - `user_role` string, nullable
    - `active` boolean, required
    - `access_mdm` integer, nullable
  - `menu_access` MenuAccessParentChild[], required
    - `parent` MenuAccessResponse, required
      - `menu_name` string, required
      - `access` integer, required
    - `children` MenuAccessResponse[], nullable
      - `menu_name` string, required
      - `access` integer, required
  - `user_firm_details` FirmDetail[], required
    - `lscode` string, required
    - `Firm_Name` string, required
    - `firm_code` string, required
    - `firm_logo` string, required
  - `user_subscription_details` SubscriptionDetail[], required
    - `lscode` string, required
    - `eligibleDays` integer, required
    - `eligibleGraceDays` integer, required
    - `subscriptionStatus` integer, required
    - `SubcriptionStart` string, required
    - `SubcriptionExpiry` string, required

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