> ## Documentation Index
> Fetch the complete documentation index at: https://learn.nexudus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create DocumentTemplate

> Create a new DocumentTemplate record.

A DocumentTemplate is a location-scoped reusable layout for generating customer, booking, contract, and proposal documents. Designer templates (Editor = Designer) are authored as a design (DesignJson) with fields, conditions, repeats and signature blocks for a DataContext and compiled to Liquid HTML; Classic templates use Liquid source or an uploaded mail-merge document.

## Authentication

<Note>
  This endpoint requires OAuth2 authentication. Include a valid bearer token in the `Authorization` header.
  The authenticated user must be a full unrestricted administrator or have the **`DocumentTemplate-Create`** role.
</Note>

## Enums

<Accordion title="eDocumentTemplateFormat — TemplateOutputFormat values">
  | Value | Name |
  | - | - |
  | 1 | Html |
  | 2 | Word |
  | 3 | Binary |
</Accordion>

## Request Body

### Required Fields

<ParamField body="BusinessId" type="integer" required>
  ID of the required location that owns this document template; only operators linked to that location can see or use it..
</ParamField>

<ParamField body="Name" type="string" required>
  Required name used to identify this document template to operators; also used as the file name of documents generated from it..
</ParamField>

<ParamField body="TemplateOutputFormat" type="integer" required>
  Selects the generated format: Html, Word (Liquid source converted to a Word document) or Binary (the uploaded BinaryDocument used for mail merge, so it only makes sense together with an uploaded file). Saving a Designer template forces this back to Html..
</ParamField>

<ParamField body="Editor" type="integer" required>
  Which editor owns the template: Classic (uploaded Word document merged with TX Text Control, or raw Liquid HTML) or Designer (a design authored in the Document Designer and compiled to Liquid HTML). Designer templates require DataContext and DesignJson, are validated and compiled on every save, and have TemplateOutputFormat forced to Html and any uploaded BinaryDocument cleared..
</ParamField>

<ParamField body="DataContext" type="integer" required>
  What the template is about: Customer, Contract, Proposal or Booking. Decides which data roots (Location, Customer, Contract, Proposal, Booking) the design can use. Designer templates must set one of the four; saving a Designer template while this is Unspecified is rejected. Classic templates leave it Unspecified..
</ParamField>

### Optional Fields

<ParamField body="Document" type="string">
  Liquid HTML source rendered for Classic templates when TemplateOutputFormat is Html or Word. The variables available come from the data context built for the record the document is generated for (Location, Customer, Contract, Proposal and Booking roots), falling back to a small legacy set when no context can be built. For Designer templates this is generated from DesignJson on every save, so any value sent here is overwritten; change DesignJson instead..
</ParamField>

<ParamField body="NewBinaryDocumentUrl" type="string">
  URL of a new file to upload as the binary document.
</ParamField>

<ParamField body="ClearBinaryDocumentFile" type="boolean">
  Set to true to remove the current binary document file.
</ParamField>

<ParamField body="DesignJson" type="string">
  Document Designer design (JSON, schema version 1) for Designer templates, holding the blocks, fields, conditions, repeats and signature blocks. Validate it with the document\_template\_designer tool before saving; the platform validates it again and compiles it into Document (Liquid HTML) on save, and a failed validation aborts the save. Ignored for Classic templates..
</ParamField>

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    "https://spaces.nexudus.com/api/crm/documenttemplates" \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "BusinessId": 0,
      "Name": "",
      "TemplateOutputFormat": 0,
      "Editor": 0,
      "DataContext": 0
  }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://spaces.nexudus.com/api/crm/documenttemplates',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        BusinessId: 0,
        Name: '',
        TemplateOutputFormat: 0,
        Editor: 0,
        DataContext: 0
      })
    }
  );

  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://spaces.nexudus.com/api/crm/documenttemplates',
      headers={
          'Authorization': 'Bearer YOUR_TOKEN',
          'Content-Type': 'application/json'
      },
      json={
          'BusinessId': 0,
          'Name': '',
          'TemplateOutputFormat': 0,
          'Editor': 0,
          'DataContext': 0
      }
  )

  data = response.json()
  ```
</CodeGroup>

## Response

### 200

<ResponseField name="Status" type="integer">
  HTTP status code. `200` on success.
</ResponseField>

<ResponseField name="Message" type="string">
  A human-readable message confirming the creation.
</ResponseField>

<ResponseField name="Value" type="object">
  Contains the `Id` of the newly created record.
</ResponseField>

<ResponseField name="WasSuccessful" type="boolean">
  `true` if the documenttemplate was created successfully.
</ResponseField>

<ResponseField name="Errors" type="array">
  `null` on success.
</ResponseField>

```json Example Response theme={null}
{
  "Status": 200,
  "Message": "DocumentTemplate was successfully created.",
  "Value": {
    "Id": 87654321
  },
  "OpenInDialog": false,
  "OpenInWindow": false,
  "RedirectURL": null,
  "JavaScript": null,
  "UpdatedOn": "2025-01-15T10:30:00Z",
  "UpdatedBy": "admin@example.com",
  "Errors": null,
  "WasSuccessful": true
}
```

### 400

<ResponseField name="Message" type="string">
  A summary of the validation error(s), in the format `PropertyName: error message`.
</ResponseField>

<ResponseField name="Value" type="any">
  `null` on validation failure.
</ResponseField>

<ResponseField name="Errors" type="object[]">
  Array of validation errors.

  <Expandable>
    <ResponseField name="AttemptedValue" type="any">
      The value that was submitted for the field, or `null` if missing.
    </ResponseField>

    <ResponseField name="Message" type="string">
      The validation error message.
    </ResponseField>

    <ResponseField name="PropertyName" type="string">
      The name of the property that failed validation.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="WasSuccessful" type="boolean">
  `false` when the request fails validation.
</ResponseField>

```json Example Response theme={null}
{
  "Message": "Name: is a required field",
  "Value": null,
  "Errors": [
    {
      "AttemptedValue": null,
      "Message": "is a required field",
      "PropertyName": "Name"
    }
  ],
  "WasSuccessful": false
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.