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

# Templates

> Save a configured package as a reusable template, then create new packages from it with a single TemplateCode instead of rebuilding documents, stakeholders, and fields each time.

A **package template** captures everything that defines a package - its documents, stakeholders,
actors, placed elements, and settings - and stores it under a reusable code. Once you have a
template, you can create a new package from it by passing a single `TemplateCode`, instead of
sending the documents, fields, and process again on every call.

Templates are worth setting up when you send the same kind of package repeatedly: a standard NDA,
an employment contract, an onboarding pack. If the documents and field layout are stable and only
the signer changes from one send to the next, a template removes almost all of the per-call
construction work and keeps every package consistent.

## Prerequisites

* A valid access token or Basic Auth credentials - see [Platform Access](/docs/nsev/getting-started/basic-setup)
* Your tenant's base URL set as `BASE_URL`
* A package you have already built and want to reuse (for creating a template), or an existing
  `TemplateCode` (for creating packages from one)

All examples use `Bearer` authentication. Replace the token and variable values with your own.

***

## Create a template from a package

Build a package the way you normally would - add its documents, stakeholders, actors, and fields -
but leave it in `Draft` status. Then save it as a template with `POST /packages/{packageId}/template`.
The only field in the body is `TemplateName`, which must be unique within the package's document
group.

```bash theme={null}
curl -X POST "$BASE_URL/packages/$PACKAGE_ID/template" \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -H "User-Agent: MyApp/1.0" \
  -d '{
    "TemplateName": "Standard NDA"
  }'
```

The response returns the template's code. Save it - this is what you pass when creating packages
from the template.

```json theme={null}
{
  "TemplateCode": "00001"
}
```

<Note>
  The source package must be in `Draft` status. Saving a package that has already been activated as a
  template returns `409 Conflict`. Build and configure the package, then save it as a template before
  you activate any signing flow.
</Note>

Everything that defines the package is stored in the template, so you can generate templates on the
fly as part of an automated flow - for example, build a canonical package once during setup and
save it as a template your integration reuses from then on.

***

## List available templates

Retrieve the templates available in your tenant, with their codes, using `GET /templates`:

```bash theme={null}
curl "$BASE_URL/templates" \
  -H "Authorization: Bearer {access_token}" \
  -H "User-Agent: MyApp/1.0"
```

Each item gives you the template `Name` and the `TemplateCode` you pass when creating a package:

```json theme={null}
{
  "PageSize": 20,
  "Total": 2,
  "Items": [
    { "Name": "Standard NDA", "TemplateCode": "00001" },
    { "Name": "Employment contract", "TemplateCode": "00002" }
  ]
}
```

The endpoint accepts optional query parameters to page and filter the list: `pageNumber` and
`pageSize` for pagination, `documentGroupCode` to return only templates in a given document group,
`sort` (`asc` or `desc`), and `createdAfter` / `createdBefore` to filter by creation date.

***

## Create a package from a template

To create a package from a template, call `POST /packages` with a `TemplateCode`. The package is
pre-populated with everything defined in the template.

```bash theme={null}
curl -X POST "$BASE_URL/packages" \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -H "User-Agent: MyApp/1.0" \
  -d '{
    "Initiator": "sender@yourcompany.com",
    "TemplateCode": "00001",
    "Name": "NDA - Acme Corp"
  }'
```

When you create a package from a template, the parameters behave as follows:

| Parameter            | Behavior                                                                                |
| -------------------- | --------------------------------------------------------------------------------------- |
| `Initiator`          | **Required.** The email address of the user who will send the package.                  |
| `TemplateCode`       | **Required.** Selects the template the package is built from.                           |
| `Name`               | Optional. Overrides the package name; otherwise the template's value is used.           |
| `ExternalReference`  | Optional. Your own reference for the package.                                           |
| `ProofCorrelationId` | Optional.                                                                               |
| All other settings   | Taken from the template - any values you pass for them are overwritten by the template. |

In other words, `Initiator` is the only thing you must supply beyond the `TemplateCode`. You can
override `Name`, `ExternalReference`, and `ProofCorrelationId`, but everything else - documents,
stakeholders, fields, callbacks, theme, and other package settings - comes from the template and
cannot be overridden in this call.

The response is the created package, in the same shape as
[Get package](/docs/nsev/api-reference/packages/get-package). As with any package, you
can continue to add or change information with additional API calls after it is created.

### Templates and super calls

A template cannot be combined with a super call.

<Warning>
  The super call inlines documents, stakeholders, actors, and elements directly in the
  `POST /packages` body; creating from a template instead inherits all of that from the
  `TemplateCode`. Pass one or the other, not both. See
  [Instant package](/docs/nsev/build/tutorials/instant-package) for the super-call approach.
</Warning>

### Placing template fields by marker

If the template defines unplaced elements that are matched to documents by text markers, the
`SingleMarkerMatchPerElement` parameter controls how those element definitions are consumed as
documents are confirmed:

```json theme={null}
{
  "Initiator": "sender@yourcompany.com",
  "TemplateCode": "00001",
  "SingleMarkerMatchPerElement": true
}
```

* `false` (the default, or `null`): an element definition can be matched by markers in multiple
  documents, and cleanup of any remaining unplaced elements is deferred.
* `true`: each element definition can be matched by only one marker during document confirmation,
  and the definition is removed once it has been placed.

On package submit, the remaining `UnplacedElements` will be disregarded and removed.

For more on markers and the other ways to position fields, see
[Field positioning](/docs/nsev/build/guides/field-positioning).

***

## When to use a template

Templates pay off when the structure of a package is stable and repeated:

* **Recurring documents** - the same contract, form, or agreement sent many times.
* **Stable field layouts** - signing fields, checkboxes, and text fields always in the same place.
* **Consistency** - every package built the same way, with the same settings, reducing the chance
  of a per-call mistake.

If each package is one-off, or the documents and field positions change every time, building the
package directly - step by step in [Send a document for signing](/docs/nsev/build/tutorials/send-for-signing),
or all at once with an [Instant package](/docs/nsev/build/tutorials/instant-package) - is
simpler than maintaining a template.

***

## Next steps

* Build a package step by step before saving it as a template in [Send a document for signing](/docs/nsev/build/tutorials/send-for-signing)
* Create everything in a single call (without a template) with an [Instant package](/docs/nsev/build/tutorials/instant-package)
* Position template fields with coordinates, markers, or existing form fields in [Field positioning](/docs/nsev/build/guides/field-positioning)
* Understand how documents, stakeholders, actors, and elements relate in [The package model](/docs/nsev/build/concepts/package-model)
