---
title: "Create Template"
method: POST
path: "/api/MobileApp/templates/create"
tags: ["MobileApp"]
---

# Create Template

`POST /api/MobileApp/templates/create`

## Request

- Base URL: `https://api.leapsurgebi.com` (the document declares no server; this is the origin it was published from)
- URL: `https://api.leapsurgebi.com/api/MobileApp/templates/create`
- Auth: OAuth 2
  - Password
  - Token URL: `/auth/token`
- TypeScript: <https://skmtc.dev/leapsurgebi/apis/leapsurgeapi/docs/api/MobileApp/templates/create/post.ts> (a function with typed inputs; its response is checked against the schema)

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

**Purpose**:
Creates a new template in the database for the provided template data. It generates a unique template code, checks for existing templates, and adds the new template and associated pages to the database.

**URL**:
`POST /templates/create`

**Headers**:
- `Customer_Key` (str, required): Encoded customer key for authorization.

**Request Body**:
- `template_data` (TemplateDataRequest): The data for the template, including application code, report code, template name, and other details.

**Process**:
1. Decode and validate the `Customer_Key`.
2. Iterate through each item in `template_data`.
3. Generate a unique template code.
4. Check if a template already exists for the report code.
5. Create a new template and add it to the database.
6. If `is_page` is True, create associated pages.
7. Update the serial number for the template code.

**Response**:
- Returns a success message if the template is created successfully.
- Returns error messages if the customer key is invalid, a template already exists, or a page already exists.

**Error Handling**:
- Catches exceptions and returns a 500 error with the exception message.

## Headers

- `Customer-Key` string, required

## Request body

- TemplateDataRequest
  - `data` TemplateData[], required
    - `id` string, nullable
    - `status` boolean, required
    - `app_code` string, required
    - `template_name` string, required
    - `report_code` string, required
    - `is_page` boolean, required
    - `page_list` string[], nullable
    - `modified_by` string, nullable
    - `modified_on` string, nullable

## Response `200`

Successful Response

- unknown

## Other responses

- `422`: Validation Error

## Changes

- **2026-09-24** `23b42df3193a`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/leapsurgebi/apis/leapsurgeapi/changes/api/MobileApp/templates/create/post.md)

---

[API](https://skmtc.dev/leapsurgebi/apis/leapsurgeapi.md) - [All operations](https://skmtc.dev/leapsurgebi/apis/leapsurgeapi/llms.txt) - [OpenAPI document](https://skmtc.dev/leapsurgebi/apis/leapsurgeapi/revisions/13653cb8ee76?raw)
