> For the complete documentation index, see [llms.txt](https://apidocs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.akinon.com/commerce-openapis/admin/templates/partially-update-a-stored-template.md).

# Partially update a stored template

Updates one or more fields of a stored template. Only the fields included in the request body are changed; omitted fields keep their stored values, `is_active` included. This is the operation to use to reactivate a record that was deleted, by sending `is_active` as `true`.

Send `language` together with `name` whenever the name changes: a request that carries `name` without `language` cannot complete the uniqueness check and fails with a server error.

A non-empty `sites` array replaces the stored sites completely rather than adding to them, while an omitted or empty array leaves them untouched.

```json
{"openapi":"3.1.0","info":{"title":"Admin API","version":"1.0.0"},"tags":[{"name":"Templates","description":"Administrative endpoints for **stored templates** — the template sources kept in the database and rendered in place of the template files shipped with the project. They are how the markup of an email, an SMS message or a storefront page is changed for a single store, or per language, without a deployment.\n\nA stored template does not introduce a new template: it overrides an existing one. Its `name` is the path of the template file it stands in for — `emails/orders/completed.html`, for example — and each record is bound to one language and to one or more sites. When that template is rendered, the stored source is used if a record matches the name, the language of the request and the current site; otherwise the file on disk is used, so removing or deactivating a record restores the original template.\n\n## Core Capabilities\n\n**1. Listing & Filtering**\n* Retrieve a paginated list of stored templates, ordered by name ascending unless the `sort` parameter says otherwise.\n* Filter by name, by active state and by site. Names match the whole value exactly; a partial name returns an empty page.\n* Deactivated templates stay in the list — filter on `is_active` to separate them from the ones in use.\n\n**2. Full CRUD**\n* Store a template for a language and one or more sites, fully or partially update it, and deactivate it.\n* `DELETE` **deactivates** the record rather than removing it. See **Deleting a Template** for what that means for the name.\n\n**3. Overridable Template Names**\n* The names of the email and SMS templates the platform sends are listed by a dedicated operation, so a client does not have to know the template paths in advance.\n\n**4. Site & Language Binding**\n* A name is normally stored once per language and site, which is what allows one store to override a template for one language only. See **Uniqueness** for the case where that rule is not enforced.\n\n## How a Stored Template Is Used\n\nStoring a record is not by itself enough for it to be rendered. All of the following must hold at the moment the template is rendered:\n\n| Condition | Detail |\n|-----------|--------|\n| The database loader is enabled | The template engine of the deployment must be configured to look in the database. See **Dynamic Settings & Environment Variables** — in a deployment that is not configured for it, stored templates are accepted by these endpoints but never rendered. |\n| The name matches exactly | The `name` must equal the path of the template being rendered, extension included. A name that differs by a character, or that is missing the extension, overrides nothing. |\n| The record is active | A record whose `is_active` is `false` is skipped, and the template file is used instead. |\n| A site matches | The record must list the site the request is served for. A record with no sites is never rendered. |\n| The language matches | The record must be stored for the language of the request. When no record exists for that language, the record stored for the default language of the deployment is used; when there is none, the template file is used. |\n\nTwo further points are worth knowing:\n\n* **Names beginning with `admin/` are never served from the database.** Management-panel templates are always read from disk.\n* **Changes are not visible immediately.** The lookup is cached — for up to five minutes in a standard deployment — so a newly stored, updated or deactivated template takes a few minutes to take effect on the storefront. This applies to deactivation as well. A deployment that also configures the shorter cache layers of the platform stacks a one-minute and a three-minute layer in front of that one, which can stretch the wait further.\n\n## Fields\n\n| Field | Description |\n|-------|-------------|\n| `pk` | Unique identifier of the record. Assigned by the server; ignored if sent. |\n| `name` | The path of the template being overridden, at most 100 characters. Required. Surrounding whitespace and any leading slashes are removed before the value is stored, so `/emails/base.html` is stored as `emails/base.html`. |\n| `content` | The template source. Required and may not be empty. It is stored as sent and is not checked for syntax errors, so a record with a broken template is accepted here and fails when the template is rendered. |\n| `language` | The language the record applies to. Required, and must be one of the languages configured for the deployment. |\n| `is_active` | Whether the record is used when the template is rendered. Optional; defaults to `true`. |\n| `sites` | The sites the record applies to, given as an array of site identifiers. Optional — see **Site Binding** for what omitting it means on each operation. |\n| `created_date` | When the record was created. Read-only. |\n| `modified_date` | When the record was last modified. Read-only. |\n\n## Site Binding\n\nThe `sites` array behaves differently on each operation, and an empty array is not a way to clear it:\n\n| Operation | Behaviour when `sites` is omitted or empty |\n|-----------|-------------------------------------------|\n| Create | The record is bound to the current site of the request. |\n| Full and partial update | The stored sites are left untouched. There is no way to unbind every site through these endpoints; send the sites the record should apply to instead. |\n\nA non-empty array replaces the stored sites completely rather than adding to them. Every identifier must belong to an existing site; an unknown identifier fails the request.\n\n## Uniqueness\n\nA name is meant to be stored only once per site and language. A create or update that repeats an existing combination is rejected with a message naming the site and the language that conflict; the message is returned in the language of the request, so match on the response status rather than on its wording.\n\nThe check covers deactivated records too, so a name occupied by a deactivated record cannot be stored again — see **Deleting a Template**.\n\nWhich sites the check runs against depends on the request:\n\n| Request | Sites checked |\n|---------|---------------|\n| Create without `sites` | The current site of the request. |\n| Create or update with a non-empty `sites` | The sites in the request. |\n| Update without `sites` | The sites the record is already bound to. |\n| Any request with an empty `sites` array | None — and with no site to check against, **the check is skipped entirely**. |\n\n> **Important:** Send these requests as JSON. A form-encoded request always carries `sites` as an empty array, even when the field is left out of the form, and the uniqueness check is therefore never applied to it: the duplicate is accepted and stored. Two records with the same name, language and site break the storefront lookup for that template, because the lookup expects at most one.\n\n## Deleting a Template\n\n> **Important:** `DELETE` does not remove the record. It sets `is_active` to `false` and returns `204 No Content`; the record keeps appearing in the list and can be retrieved by its identifier.\n\nTwo consequences follow. The template file on disk takes over again once the cached lookup expires, which is the intended effect. But the name stays occupied: storing the same name for the same site and language again is rejected, and the way to bring the template back is to set `is_active` to `true` on the existing record rather than to create a new one.\n\n## Partially Updating a Name\n\nWhen a partial update changes `name`, include `language` in the same request. A partial update that sends `name` without `language` cannot complete the uniqueness check and fails with a server error — unless there is no site to check against, in which case the check does not run and the request succeeds. A full update is unaffected, because `language` is required there.\n\n## Sorting\n\nThe `sort` parameter accepts `pk`, `name`, `content`, `language`, `is_active`, `created_date` and `modified_date`. Prefix a field with a hyphen for descending order. Any other value is ignored and the default ordering by name is kept.\n\n> **Do not sort by `sites`.** The value is accepted, but a record bound to several sites is then repeated once per site while the page count keeps counting records rather than rows — so the page fills up with repetitions and other records fall off it entirely.\n\nSorting by `content` is accepted too and orders records by their raw template source, which rarely produces a useful order.\n\n## Dynamic Settings & Environment Variables\n\nNo dynamic setting changes the behaviour of the endpoints described here: every action stays available and behaves identically regardless of how the settings are configured. The two settings below relate to the templates managed here at the point where they are **used**.\n\n| Key | Type | Default | Effect |\n|-----|------|---------|--------|\n| `DB_TEMPLATES_PREFIXES` | array of strings | `[\"emails\", \"sms\"]` | **Deprecated and without effect.** It once did two things: it rejected a `name` whose first path segment was not one of these prefixes, and it kept the database from being consulted for any other template. Both checks were removed, and the value is no longer read anywhere — a name under any prefix is stored and overrides its template all the same. |\n| `DISABLED_EMAIL_TEMPLATES` | object mapping a template path (without its extension) to a boolean | every email template enabled, except the order-preparing email, which is disabled | A per-template kill switch for outbound emails. It does not affect these endpoints — a template stored for a disabled email is created and returned normally — but the email is never sent, so the stored template is never rendered. |\n\n**Environment variables:** The following deployment configuration decides whether and how stored templates are used. None of it is read by these endpoints themselves, so a misconfigured deployment gives no error here.\n\n| Variable | Effect |\n|----------|--------|\n| `TEMPLATE_LOADER` | **Decides whether stored templates are used at all.** The database is consulted only while this is set to the loader that reads templates from the database and falls back to the files on disk (`omnicore.dbtemplates.jinja_loaders.DatabaseAndFileSystemLoader`); that is the default in a cloud-mode deployment. In a deployment that keeps the file-system-only loader — which is the default outside cloud mode — records created through these endpoints are stored but never rendered. |\n| `LANGUAGES` | The languages a record may be stored for. A `language` outside this list fails validation. Given as comma-separated `code=name` pairs, for example `tr-tr=Turkish,en-us=English`. |\n| `LANGUAGE_CODE` | The default language of the deployment, used as the fallback when no record is stored for the language of the request. |\n| `DB_TEMPLATES_MODEL` | Selects which record type these endpoints manage. Unlike the three above it is not read from an environment variable but from the deployment configuration itself, and it is left unset in a standard deployment — the templates of the content-management module are managed then. |"}],"servers":[{"description":"Omnitron Remote Proxy (external access — recommended)","url":"https://{omnitron_url}/api/v1/remote/{channel_id}","variables":{"omnitron_url":{"default":"sandbox.akinon.com","description":"Omnitron server URL (e.g., {omnitron.akinon.com})"},"channel_id":{"default":"1","description":"The channel identifier the remote request is routed through"}}},{"description":"Commerce API Server (internal / direct access only)","url":"https://{commerce_url}/api/v1","variables":{"commerce_url":{"default":"sandbox.akinon.com","description":"Internal commerce server URL, reachable only from within the Omnitron network"}}}],"security":[{"tokenAuth":[]}],"components":{"securitySchemes":{"tokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"Token credential sent in the Authorization header, in the form: `Token <your-token>`. Requires a staff (admin) account."}},"schemas":{"TemplatePatchRequest":{"type":"object","description":"Request body for partially updating a stored template. Send only the fields you want to change; every field is optional and omitted fields keep their stored values, `is_active` included.\n\nSend `language` together with `name` whenever the name changes — a request carrying `name` without `language` fails with a server error.","properties":{"name":{"type":"string","maxLength":100,"description":"The path of the template to override. Send `language` in the same request when this field is present."},"content":{"type":"string","description":"The template source. May not be empty."},"language":{"type":"string","description":"The language the record applies to."},"is_active":{"type":"boolean","description":"Whether the record is used when the template is rendered. Send `true` to bring back a record that was deleted."},"sites":{"type":"array","description":"Identifiers of the sites the record applies to. A non-empty array replaces the stored sites; an empty array leaves them untouched.","items":{"type":"integer"}}}},"Template":{"type":"object","description":"A stored template returned by the API. The full template source is part of the response, and deactivated records are returned in the same shape as active ones.","properties":{"pk":{"type":"integer","readOnly":true,"description":"Unique identifier of the stored template."},"name":{"type":"string","maxLength":100,"description":"The path of the template being overridden, as it was stored — without surrounding whitespace and without a leading slash."},"content":{"type":"string","description":"The template source, returned exactly as it was stored."},"language":{"type":"string","description":"The language the record applies to, as one of the language codes configured for the deployment."},"is_active":{"type":"boolean","description":"Whether the record is used when the template is rendered. `false` on a record that was deleted through this API."},"sites":{"type":"array","description":"Identifiers of the sites the record is bound to. Empty on a record that is bound to no site, which is never rendered.","items":{"type":"integer"}},"created_date":{"type":"string","format":"date-time","readOnly":true,"description":"When the record was created."},"modified_date":{"type":"string","format":"date-time","readOnly":true,"description":"When the record was last modified."}},"required":["pk","name","content","language","is_active","sites","created_date","modified_date"]},"ValidationError":{"type":"object","description":"Returned when the request contains invalid or missing data. Errors are grouped by the field they apply to: each key is the name of a field from the request and its value is a list of one or more messages describing what is wrong with that field. Messages that do not belong to any single field are grouped under `non_field_errors`.","properties":{"non_field_errors":{"type":"array","description":"Error messages that apply to the request as a whole rather than to a specific field.","items":{"type":"string"}}},"additionalProperties":{"type":"array","description":"The list of error messages for the field named by the key.","items":{"type":"string"}}},"Error":{"type":"object","description":"An error response.","properties":{"detail":{"type":"string","description":"A human-readable description of the error."}},"additionalProperties":true}},"responses":{"ValidationError":{"description":"The request contains invalid or missing data.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"Unauthorized":{"description":"Authentication credentials were not provided or are invalid.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Forbidden":{"description":"The authenticated user does not have administrator privileges.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"TemplateNotFound":{"description":"No stored template exists with the given identifier. Deactivated records are still retrievable, so this answer means the record does not exist at all.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"paths":{"/templates/{id}/":{"patch":{"tags":["Templates"],"operationId":"partialUpdateTemplate","summary":"Partially update a stored template","description":"Updates one or more fields of a stored template. Only the fields included in the request body are changed; omitted fields keep their stored values, `is_active` included. This is the operation to use to reactivate a record that was deleted, by sending `is_active` as `true`.\n\nSend `language` together with `name` whenever the name changes: a request that carries `name` without `language` cannot complete the uniqueness check and fails with a server error.\n\nA non-empty `sites` array replaces the stored sites completely rather than adding to them, while an omitted or empty array leaves them untouched.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TemplatePatchRequest"}}}},"responses":{"200":{"description":"The updated stored template.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Template"}}}},"400":{"$ref":"#/components/responses/ValidationError"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/TemplateNotFound"}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://apidocs.akinon.com/commerce-openapis/admin/templates/partially-update-a-stored-template.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
